mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 18:48:08 +00:00 
			
		
		
		
	Database gRPC plugins (#3666)
* Start work on context aware backends * Start work on moving the database plugins to gRPC in order to pass context * Add context to builtin database plugins * use byte slice instead of string * Context all the things * Move proto messages to the dbplugin package * Add a grpc mechanism for running backend plugins * Serve the GRPC plugin * Add backwards compatibility to the database plugins * Remove backend plugin changes * Remove backend plugin changes * Cleanup the transport implementations * If grpc connection is in an unexpected state restart the plugin * Fix tests * Fix tests * Remove context from the request object, replace it with context.TODO * Add a test to verify netRPC plugins still work * Remove unused mapstructure call * Code review fixes * Code review fixes * Code review fixes
This commit is contained in:
		| @@ -1,6 +1,7 @@ | ||||
| package mssql | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"database/sql" | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
| @@ -18,6 +19,8 @@ import ( | ||||
|  | ||||
| const msSQLTypeName = "mssql" | ||||
|  | ||||
| var _ dbplugin.Database = &MSSQL{} | ||||
|  | ||||
| // MSSQL is an implementation of Database interface | ||||
| type MSSQL struct { | ||||
| 	connutil.ConnectionProducer | ||||
| @@ -60,8 +63,8 @@ func (m *MSSQL) Type() (string, error) { | ||||
| 	return msSQLTypeName, nil | ||||
| } | ||||
|  | ||||
| func (m *MSSQL) getConnection() (*sql.DB, error) { | ||||
| 	db, err := m.Connection() | ||||
| func (m *MSSQL) getConnection(ctx context.Context) (*sql.DB, error) { | ||||
| 	db, err := m.Connection(ctx) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| @@ -71,13 +74,13 @@ func (m *MSSQL) getConnection() (*sql.DB, error) { | ||||
|  | ||||
| // CreateUser generates the username/password on the underlying MSSQL secret backend as instructed by | ||||
| // the CreationStatement provided. | ||||
| func (m *MSSQL) CreateUser(statements dbplugin.Statements, usernameConfig dbplugin.UsernameConfig, expiration time.Time) (username string, password string, err error) { | ||||
| func (m *MSSQL) CreateUser(ctx context.Context, statements dbplugin.Statements, usernameConfig dbplugin.UsernameConfig, expiration time.Time) (username string, password string, err error) { | ||||
| 	// Grab the lock | ||||
| 	m.Lock() | ||||
| 	defer m.Unlock() | ||||
|  | ||||
| 	// Get the connection | ||||
| 	db, err := m.getConnection() | ||||
| 	db, err := m.getConnection(ctx) | ||||
| 	if err != nil { | ||||
| 		return "", "", err | ||||
| 	} | ||||
| @@ -138,7 +141,7 @@ func (m *MSSQL) CreateUser(statements dbplugin.Statements, usernameConfig dbplug | ||||
| } | ||||
|  | ||||
| // RenewUser is not supported on MSSQL, so this is a no-op. | ||||
| func (m *MSSQL) RenewUser(statements dbplugin.Statements, username string, expiration time.Time) error { | ||||
| func (m *MSSQL) RenewUser(ctx context.Context, statements dbplugin.Statements, username string, expiration time.Time) error { | ||||
| 	// NOOP | ||||
| 	return nil | ||||
| } | ||||
| @@ -146,13 +149,13 @@ func (m *MSSQL) RenewUser(statements dbplugin.Statements, username string, expir | ||||
| // RevokeUser attempts to drop the specified user. It will first attempt to disable login, | ||||
| // then kill pending connections from that user, and finally drop the user and login from the | ||||
| // database instance. | ||||
| func (m *MSSQL) RevokeUser(statements dbplugin.Statements, username string) error { | ||||
| func (m *MSSQL) RevokeUser(ctx context.Context, statements dbplugin.Statements, username string) error { | ||||
| 	if statements.RevocationStatements == "" { | ||||
| 		return m.revokeUserDefault(username) | ||||
| 		return m.revokeUserDefault(ctx, username) | ||||
| 	} | ||||
|  | ||||
| 	// Get connection | ||||
| 	db, err := m.getConnection() | ||||
| 	db, err := m.getConnection(ctx) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| @@ -191,9 +194,9 @@ func (m *MSSQL) RevokeUser(statements dbplugin.Statements, username string) erro | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (m *MSSQL) revokeUserDefault(username string) error { | ||||
| func (m *MSSQL) revokeUserDefault(ctx context.Context, username string) error { | ||||
| 	// Get connection | ||||
| 	db, err := m.getConnection() | ||||
| 	db, err := m.getConnection(ctx) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Brian Kassouf
					Brian Kassouf