vault/builtin/logical/database/mockv5.go
hashicorp-copywrite[bot] 0b12cdcfd1
[COMPLIANCE] License changes (#22290)
* Adding explicit MPL license for sub-package.

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Adding explicit MPL license for sub-package.

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Updating the license from MPL to Business Source License.

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl.

* add missing license headers

* Update copyright file headers to BUS-1.1

* Fix test that expected exact offset on hcl file

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Sarah Thompson <sthompson@hashicorp.com>
Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
2023-08-10 18:14:03 -07:00

95 lines
2.1 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package database
import (
"context"
"fmt"
"time"
log "github.com/hashicorp/go-hclog"
v5 "github.com/hashicorp/vault/sdk/database/dbplugin/v5"
)
const mockV5Type = "mockv5"
// MockDatabaseV5 is an implementation of Database interface
type MockDatabaseV5 struct {
config map[string]interface{}
}
var _ v5.Database = &MockDatabaseV5{}
// New returns a new in-memory instance
func New() (interface{}, error) {
db := MockDatabaseV5{}
return db, nil
}
// Run instantiates a MongoDB object, and runs the RPC server for the plugin
func RunV5() error {
dbType, err := New()
if err != nil {
return err
}
v5.Serve(dbType.(v5.Database))
return nil
}
// Run instantiates a MongoDB object, and runs the RPC server for the plugin
func RunV6Multiplexed() error {
v5.ServeMultiplex(New)
return nil
}
func (m MockDatabaseV5) Initialize(ctx context.Context, req v5.InitializeRequest) (v5.InitializeResponse, error) {
log.Default().Info("Initialize called",
"req", req)
config := req.Config
config["from-plugin"] = "this value is from the plugin itself"
resp := v5.InitializeResponse{
Config: req.Config,
}
return resp, nil
}
func (m MockDatabaseV5) NewUser(ctx context.Context, req v5.NewUserRequest) (v5.NewUserResponse, error) {
log.Default().Info("NewUser called",
"req", req)
now := time.Now()
user := fmt.Sprintf("mockv5_user_%s", now.Format(time.RFC3339))
resp := v5.NewUserResponse{
Username: user,
}
return resp, nil
}
func (m MockDatabaseV5) UpdateUser(ctx context.Context, req v5.UpdateUserRequest) (v5.UpdateUserResponse, error) {
log.Default().Info("UpdateUser called",
"req", req)
return v5.UpdateUserResponse{}, nil
}
func (m MockDatabaseV5) DeleteUser(ctx context.Context, req v5.DeleteUserRequest) (v5.DeleteUserResponse, error) {
log.Default().Info("DeleteUser called",
"req", req)
return v5.DeleteUserResponse{}, nil
}
func (m MockDatabaseV5) Type() (string, error) {
log.Default().Info("Type called")
return mockV5Type, nil
}
func (m MockDatabaseV5) Close() error {
log.Default().Info("Close called")
return nil
}