mock

package module
v0.0.0-...-87f2fe3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2023 License: MPL-2.0 Imports: 7 Imported by: 0

README

Vault Mock Database Plugin

Mock is an example database engine plugin for HashiCorp Vault. It is meant for demonstration purposes only and should never be used in production.

Usage

All commands can be run using the provided Makefile. However, it may be instructive to look at the commands to gain a greater understanding of how Vault registers plugins. Using the Makefile will result in running the Vault server in dev mode. Do not run Vault in dev mode in production. The dev server allows you to configure the plugin directory as a flag, and automatically registers plugin binaries in that directory. In production, plugin binaries must be manually registered.

This will build the plugin binary and start the Vault dev server:

# Build Mock plugin and start Vault dev server with plugin automatically registered
$ make

Now open a new terminal window and run the following commands:

# Open a new terminal window and export Vault dev server http address
$ export VAULT_ADDR='http://127.0.0.1:8200'

# Enable the Mock database plugin
$ make enable

# Retrieve database credentials from the secrets engine
$ vault read database/creds/mock-role
Key                Value
---                -----
lease_id           database/creds/mock-role/voIwi51mOWzhdhGK1j3Xt92g
lease_duration     5m
lease_renewable    true
password           mvYgYUC55X-K05y35H84
username           v_token_mock_role_oeshdtguahgwplg2p66b_1631316568

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() (interface{}, error)

New returns a new Mock instance

Types

type Mock

type Mock struct {
	// contains filtered or unexported fields
}

backend wraps the backend framework and adds a map for storing key value pairs

func (Mock) Close

func (m Mock) Close() error

Close terminates the database connection.

func (Mock) Connection

func (m Mock) Connection(ctx context.Context) (*MockClient, error)

Connection creates a database connection

func (*Mock) DeleteUser

DeleteUser from the database. This should not error if the user didn't exist prior to this call.

func (*Mock) Initialize

Initialize the database plugin. This is the equivalent of a constructor for the database object itself.

func (*Mock) NewUser

NewUser creates a new user within the database. This user is temporary in that it will exist until the TTL expires.

func (*Mock) Type

func (n *Mock) Type() (string, error)

Type returns the Name for the particular database backend implementation. This type name is usually set as a constant within the database backend implementation, e.g. "mysql" for the MySQL database backend. This is used for things like metrics and logging. No behavior is switched on this.

func (*Mock) UpdateUser

UpdateUser updates an existing user within the database.

type MockClient

type MockClient struct {
	Username string
	Password string
	URL      string
	// contains filtered or unexported fields
}

A mock database client used as an example, in a real world this would be an external library provided by a database provider.

func NewMockClient

func NewMockClient(url, username, password string) (MockClient, error)

func (*MockClient) CreateUser

func (c *MockClient) CreateUser(username, password string) mockUser

func (*MockClient) DeleteUser

func (c *MockClient) DeleteUser(username string) error

func (*MockClient) UpdateUser

func (c *MockClient) UpdateUser(username, password string) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL