mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-11-04 04:28: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"
 | 
			
		||||
	"os"
 | 
			
		||||
@@ -30,7 +31,7 @@ func TestMSSQL_Initialize(t *testing.T) {
 | 
			
		||||
	dbRaw, _ := New()
 | 
			
		||||
	db := dbRaw.(*MSSQL)
 | 
			
		||||
 | 
			
		||||
	err := db.Initialize(connectionDetails, true)
 | 
			
		||||
	err := db.Initialize(context.Background(), connectionDetails, true)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("err: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -51,7 +52,7 @@ func TestMSSQL_Initialize(t *testing.T) {
 | 
			
		||||
		"max_open_connections": "5",
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = db.Initialize(connectionDetails, true)
 | 
			
		||||
	err = db.Initialize(context.Background(), connectionDetails, true)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("err: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -69,7 +70,7 @@ func TestMSSQL_CreateUser(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	dbRaw, _ := New()
 | 
			
		||||
	db := dbRaw.(*MSSQL)
 | 
			
		||||
	err := db.Initialize(connectionDetails, true)
 | 
			
		||||
	err := db.Initialize(context.Background(), connectionDetails, true)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("err: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -80,7 +81,7 @@ func TestMSSQL_CreateUser(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Test with no configured Creation Statememt
 | 
			
		||||
	_, _, err = db.CreateUser(dbplugin.Statements{}, usernameConfig, time.Now().Add(time.Minute))
 | 
			
		||||
	_, _, err = db.CreateUser(context.Background(), dbplugin.Statements{}, usernameConfig, time.Now().Add(time.Minute))
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		t.Fatal("Expected error when no creation statement is provided")
 | 
			
		||||
	}
 | 
			
		||||
@@ -89,7 +90,7 @@ func TestMSSQL_CreateUser(t *testing.T) {
 | 
			
		||||
		CreationStatements: testMSSQLRole,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	username, password, err := db.CreateUser(statements, usernameConfig, time.Now().Add(time.Minute))
 | 
			
		||||
	username, password, err := db.CreateUser(context.Background(), statements, usernameConfig, time.Now().Add(time.Minute))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("err: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -111,7 +112,7 @@ func TestMSSQL_RevokeUser(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	dbRaw, _ := New()
 | 
			
		||||
	db := dbRaw.(*MSSQL)
 | 
			
		||||
	err := db.Initialize(connectionDetails, true)
 | 
			
		||||
	err := db.Initialize(context.Background(), connectionDetails, true)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("err: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -125,7 +126,7 @@ func TestMSSQL_RevokeUser(t *testing.T) {
 | 
			
		||||
		RoleName:    "test",
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	username, password, err := db.CreateUser(statements, usernameConfig, time.Now().Add(2*time.Second))
 | 
			
		||||
	username, password, err := db.CreateUser(context.Background(), statements, usernameConfig, time.Now().Add(2*time.Second))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("err: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -135,7 +136,7 @@ func TestMSSQL_RevokeUser(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Test default revoke statememts
 | 
			
		||||
	err = db.RevokeUser(statements, username)
 | 
			
		||||
	err = db.RevokeUser(context.Background(), statements, username)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("err: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -144,7 +145,7 @@ func TestMSSQL_RevokeUser(t *testing.T) {
 | 
			
		||||
		t.Fatal("Credentials were not revoked")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	username, password, err = db.CreateUser(statements, usernameConfig, time.Now().Add(2*time.Second))
 | 
			
		||||
	username, password, err = db.CreateUser(context.Background(), statements, usernameConfig, time.Now().Add(2*time.Second))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("err: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -155,7 +156,7 @@ func TestMSSQL_RevokeUser(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// Test custom revoke statememt
 | 
			
		||||
	statements.RevocationStatements = testMSSQLDrop
 | 
			
		||||
	err = db.RevokeUser(statements, username)
 | 
			
		||||
	err = db.RevokeUser(context.Background(), statements, username)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("err: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user