diff --git a/builtin/logical/database/backend.go b/builtin/logical/database/backend.go index e57fa19c18..7d6ffe9c98 100644 --- a/builtin/logical/database/backend.go +++ b/builtin/logical/database/backend.go @@ -41,12 +41,12 @@ func Backend(conf *logical.BackendConfig) *databaseBackend { } b.logger = conf.Logger - b.connections = make(map[string]dbplugin.DatabaseType) + b.connections = make(map[string]dbplugin.Database) return &b } type databaseBackend struct { - connections map[string]dbplugin.DatabaseType + connections map[string]dbplugin.Database logger log.Logger *framework.Backend @@ -62,13 +62,13 @@ func (b *databaseBackend) closeAllDBs() { db.Close() } - b.connections = nil + b.connections = make(map[string]dbplugin.Database) } // This function is used to retrieve a database object either from the cached // connection map or by using the database config in storage. The caller of this // function needs to hold the backend's lock. -func (b *databaseBackend) getOrCreateDBObj(s logical.Storage, name string) (dbplugin.DatabaseType, error) { +func (b *databaseBackend) getOrCreateDBObj(s logical.Storage, name string) (dbplugin.Database, error) { // if the object already is built and cached, return it db, ok := b.connections[name] if ok { diff --git a/builtin/logical/database/dbplugin/client.go b/builtin/logical/database/dbplugin/client.go index 93db86595a..8cfc3aad00 100644 --- a/builtin/logical/database/dbplugin/client.go +++ b/builtin/logical/database/dbplugin/client.go @@ -29,7 +29,7 @@ func (dc *DatabasePluginClient) Close() error { // newPluginClient returns a databaseRPCClient with a connection to a running // plugin. The client is wrapped in a DatabasePluginClient object to ensure the // plugin is killed on call of Close(). -func newPluginClient(sys pluginutil.Wrapper, pluginRunner *pluginutil.PluginRunner) (DatabaseType, error) { +func newPluginClient(sys pluginutil.Wrapper, pluginRunner *pluginutil.PluginRunner) (Database, error) { // pluginMap is the map of plugins we can dispense. var pluginMap = map[string]plugin.Plugin{ "database": new(DatabasePlugin), @@ -65,7 +65,7 @@ func newPluginClient(sys pluginutil.Wrapper, pluginRunner *pluginutil.PluginRunn // ---- RPC client domain ---- -// databasePluginRPCClient implements DatabaseType and is used on the client to +// databasePluginRPCClient implements Database and is used on the client to // make RPC calls to a plugin. type databasePluginRPCClient struct { client *rpc.Client diff --git a/builtin/logical/database/dbplugin/databasemiddleware.go b/builtin/logical/database/dbplugin/databasemiddleware.go index e28a8741e4..9ab35b740f 100644 --- a/builtin/logical/database/dbplugin/databasemiddleware.go +++ b/builtin/logical/database/dbplugin/databasemiddleware.go @@ -9,10 +9,10 @@ import ( // ---- Tracing Middleware Domain ---- -// databaseTracingMiddleware wraps a implementation of DatabaseType and executes +// databaseTracingMiddleware wraps a implementation of Database and executes // trace logging on function call. type databaseTracingMiddleware struct { - next DatabaseType + next Database logger log.Logger typeStr string @@ -79,10 +79,10 @@ func (mw *databaseTracingMiddleware) Close() (err error) { // ---- Metrics Middleware Domain ---- -// databaseMetricsMiddleware wraps an implementation of DatabaseTypes and on +// databaseMetricsMiddleware wraps an implementation of Databases and on // function call logs metrics about this instance. type databaseMetricsMiddleware struct { - next DatabaseType + next Database typeStr string } diff --git a/builtin/logical/database/dbplugin/plugin.go b/builtin/logical/database/dbplugin/plugin.go index 9a6691fbab..21812423c1 100644 --- a/builtin/logical/database/dbplugin/plugin.go +++ b/builtin/logical/database/dbplugin/plugin.go @@ -10,8 +10,8 @@ import ( log "github.com/mgutz/logxi/v1" ) -// DatabaseType is the interface that all database objects must implement. -type DatabaseType interface { +// Database is the interface that all database objects must implement. +type Database interface { Type() (string, error) CreateUser(statements Statements, usernamePrefix string, expiration time.Time) (username string, password string, err error) RenewUser(statements Statements, username string, expiration time.Time) error @@ -31,24 +31,24 @@ type Statements struct { // PluginFactory is used to build plugin database types. It wraps the database // object in a logging and metrics middleware. -func PluginFactory(pluginName string, sys pluginutil.LookWrapper, logger log.Logger) (DatabaseType, error) { +func PluginFactory(pluginName string, sys pluginutil.LookWrapper, logger log.Logger) (Database, error) { // Look for plugin in the plugin catalog pluginRunner, err := sys.LookupPlugin(pluginName) if err != nil { return nil, err } - var db DatabaseType + var db Database if pluginRunner.Builtin { // Plugin is builtin so we can retrieve an instance of the interface - // from the pluginRunner. Then cast it to a DatabaseType. + // from the pluginRunner. Then cast it to a Database. dbRaw, err := pluginRunner.BuiltinFactory() if err != nil { return nil, fmt.Errorf("error getting plugin type: %s", err) } var ok bool - db, ok = dbRaw.(DatabaseType) + db, ok = dbRaw.(Database) if !ok { return nil, fmt.Errorf("unsuported database type: %s", pluginName) } @@ -95,7 +95,7 @@ var handshakeConfig = plugin.HandshakeConfig{ // DatabasePlugin implements go-plugin's Plugin interface. It has methods for // retrieving a server and a client instance of the plugin. type DatabasePlugin struct { - impl DatabaseType + impl Database } func (d DatabasePlugin) Server(*plugin.MuxBroker) (interface{}, error) { diff --git a/builtin/logical/database/dbplugin/server.go b/builtin/logical/database/dbplugin/server.go index 3a3e233946..04cc3d7e90 100644 --- a/builtin/logical/database/dbplugin/server.go +++ b/builtin/logical/database/dbplugin/server.go @@ -8,9 +8,9 @@ import ( ) // NewPluginServer is called from within a plugin and wraps the provided -// DatabaseType implementation in a databasePluginRPCServer object and starts a +// Database implementation in a databasePluginRPCServer object and starts a // RPC server. -func NewPluginServer(db DatabaseType) { +func NewPluginServer(db Database) { dbPlugin := &DatabasePlugin{ impl: db, } @@ -35,10 +35,10 @@ func NewPluginServer(db DatabaseType) { // ---- RPC server domain ---- -// databasePluginRPCServer implements an RPC version of DatabaseType and is run -// inside a plugin. It wraps an underlying implementation of DatabaseType. +// databasePluginRPCServer implements an RPC version of Database and is run +// inside a plugin. It wraps an underlying implementation of Database. type databasePluginRPCServer struct { - impl DatabaseType + impl Database } func (ds *databasePluginRPCServer) Type(_ struct{}, resp *string) error { diff --git a/builtin/logical/database/path_config_connection.go b/builtin/logical/database/path_config_connection.go index 2a0022b4d8..f154ae1643 100644 --- a/builtin/logical/database/path_config_connection.go +++ b/builtin/logical/database/path_config_connection.go @@ -16,7 +16,7 @@ var ( respErrEmptyName = logical.ErrorResponse("Empty name attribute given") ) -// DatabaseConfig is used by the Factory function to configure a DatabaseType +// DatabaseConfig is used by the Factory function to configure a Database // object. type DatabaseConfig struct { PluginName string `json:"plugin_name" structs:"plugin_name" mapstructure:"plugin_name"` diff --git a/plugins/database/mssql/mssql.go b/plugins/database/mssql/mssql.go index b0e0ab6d41..54f2a9711a 100644 --- a/plugins/database/mssql/mssql.go +++ b/plugins/database/mssql/mssql.go @@ -15,7 +15,7 @@ import ( const msSQLTypeName = "mssql" -// MSSQL is an implementation of DatabaseType interface +// MSSQL is an implementation of Database interface type MSSQL struct { connutil.ConnectionProducer credsutil.CredentialsProducer diff --git a/plugins/helper/database/connutil/connutil.go b/plugins/helper/database/connutil/connutil.go index 6de3299e38..c43691c616 100644 --- a/plugins/helper/database/connutil/connutil.go +++ b/plugins/helper/database/connutil/connutil.go @@ -9,7 +9,7 @@ var ( errNotInitialized = errors.New("connection has not been initalized") ) -// ConnectionProducer can be used as an embeded interface in the DatabaseType +// ConnectionProducer can be used as an embeded interface in the Database // definition. It implements the methods dealing with individual database // connections and is used in all the builtin database types. type ConnectionProducer interface { diff --git a/plugins/helper/database/credsutil/credsutil.go b/plugins/helper/database/credsutil/credsutil.go index 7f388a0f76..bc35617ac2 100644 --- a/plugins/helper/database/credsutil/credsutil.go +++ b/plugins/helper/database/credsutil/credsutil.go @@ -2,7 +2,7 @@ package credsutil import "time" -// CredentialsProducer can be used as an embeded interface in the DatabaseType +// CredentialsProducer can be used as an embeded interface in the Database // definition. It implements the methods for generating user information for a // particular database type and is used in all the builtin database types. type CredentialsProducer interface {