From 10121fed37f0fc97baff017d70f1ad3360729960 Mon Sep 17 00:00:00 2001 From: Max Coulombe <109547106+maxcoulombe@users.noreply.github.com> Date: Tue, 6 Sep 2022 14:00:37 -0400 Subject: [PATCH] Prepare multiplexing support for database plugins (#16995) * prepare multiplexing support for database plugins --- changelog/16995.txt | 3 +++ .../cassandra-database-plugin/main.go | 9 ++------- .../database/hana/hana-database-plugin/main.go | 9 ++------- .../influxdb/influxdb-database-plugin/main.go | 9 ++------- .../mongodb/mongodb-database-plugin/main.go | 9 ++------- .../mssql/mssql-database-plugin/main.go | 9 ++------- .../mysql/mysql-database-plugin/main.go | 8 ++------ .../postgresql-database-plugin/main.go | 9 ++------- .../redshift/redshift-database-plugin/main.go | 18 ++++-------------- 9 files changed, 21 insertions(+), 62 deletions(-) create mode 100644 changelog/16995.txt diff --git a/changelog/16995.txt b/changelog/16995.txt new file mode 100644 index 000000000..c1adc9060 --- /dev/null +++ b/changelog/16995.txt @@ -0,0 +1,3 @@ +```release-note:improvement +plugins/multiplexing: Added multiplexing support to database plugins if run as external plugins +``` \ No newline at end of file diff --git a/plugins/database/cassandra/cassandra-database-plugin/main.go b/plugins/database/cassandra/cassandra-database-plugin/main.go index 0b9212580..4ee090364 100644 --- a/plugins/database/cassandra/cassandra-database-plugin/main.go +++ b/plugins/database/cassandra/cassandra-database-plugin/main.go @@ -5,7 +5,7 @@ import ( "os" "github.com/hashicorp/vault/plugins/database/cassandra" - dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" + "github.com/hashicorp/vault/sdk/database/dbplugin/v5" ) func main() { @@ -18,12 +18,7 @@ func main() { // Run instantiates a Cassandra object, and runs the RPC server for the plugin func Run() error { - dbType, err := cassandra.New() - if err != nil { - return err - } - - dbplugin.Serve(dbType.(dbplugin.Database)) + dbplugin.ServeMultiplex(cassandra.New) return nil } diff --git a/plugins/database/hana/hana-database-plugin/main.go b/plugins/database/hana/hana-database-plugin/main.go index 1285a8d5f..2057c36c0 100644 --- a/plugins/database/hana/hana-database-plugin/main.go +++ b/plugins/database/hana/hana-database-plugin/main.go @@ -5,7 +5,7 @@ import ( "os" "github.com/hashicorp/vault/plugins/database/hana" - dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" + "github.com/hashicorp/vault/sdk/database/dbplugin/v5" ) func main() { @@ -18,12 +18,7 @@ func main() { // Run instantiates a HANA object, and runs the RPC server for the plugin func Run() error { - dbType, err := hana.New() - if err != nil { - return err - } - - dbplugin.Serve(dbType.(dbplugin.Database)) + dbplugin.ServeMultiplex(hana.New) return nil } diff --git a/plugins/database/influxdb/influxdb-database-plugin/main.go b/plugins/database/influxdb/influxdb-database-plugin/main.go index 47284f725..c8f6c5fa1 100644 --- a/plugins/database/influxdb/influxdb-database-plugin/main.go +++ b/plugins/database/influxdb/influxdb-database-plugin/main.go @@ -5,7 +5,7 @@ import ( "os" "github.com/hashicorp/vault/plugins/database/influxdb" - dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" + "github.com/hashicorp/vault/sdk/database/dbplugin/v5" ) func main() { @@ -18,12 +18,7 @@ func main() { // Run instantiates a Influxdb object, and runs the RPC server for the plugin func Run() error { - dbType, err := influxdb.New() - if err != nil { - return err - } - - dbplugin.Serve(dbType.(dbplugin.Database)) + dbplugin.ServeMultiplex(influxdb.New) return nil } diff --git a/plugins/database/mongodb/mongodb-database-plugin/main.go b/plugins/database/mongodb/mongodb-database-plugin/main.go index 3e78ca33f..30dd5fdd7 100644 --- a/plugins/database/mongodb/mongodb-database-plugin/main.go +++ b/plugins/database/mongodb/mongodb-database-plugin/main.go @@ -5,7 +5,7 @@ import ( "os" "github.com/hashicorp/vault/plugins/database/mongodb" - dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" + "github.com/hashicorp/vault/sdk/database/dbplugin/v5" ) func main() { @@ -18,12 +18,7 @@ func main() { // Run instantiates a MongoDB object, and runs the RPC server for the plugin func Run() error { - dbType, err := mongodb.New() - if err != nil { - return err - } - - dbplugin.Serve(dbType.(dbplugin.Database)) + dbplugin.ServeMultiplex(mongodb.New) return nil } diff --git a/plugins/database/mssql/mssql-database-plugin/main.go b/plugins/database/mssql/mssql-database-plugin/main.go index d8b680cbc..37a81a660 100644 --- a/plugins/database/mssql/mssql-database-plugin/main.go +++ b/plugins/database/mssql/mssql-database-plugin/main.go @@ -5,7 +5,7 @@ import ( "os" "github.com/hashicorp/vault/plugins/database/mssql" - dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" + "github.com/hashicorp/vault/sdk/database/dbplugin/v5" ) func main() { @@ -18,12 +18,7 @@ func main() { // Run instantiates a MSSQL object, and runs the RPC server for the plugin func Run() error { - dbType, err := mssql.New() - if err != nil { - return err - } - - dbplugin.Serve(dbType.(dbplugin.Database)) + dbplugin.ServeMultiplex(mssql.New) return nil } diff --git a/plugins/database/mysql/mysql-database-plugin/main.go b/plugins/database/mysql/mysql-database-plugin/main.go index ae75b64aa..6b1505aff 100644 --- a/plugins/database/mysql/mysql-database-plugin/main.go +++ b/plugins/database/mysql/mysql-database-plugin/main.go @@ -5,7 +5,7 @@ import ( "os" "github.com/hashicorp/vault/plugins/database/mysql" - dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" + "github.com/hashicorp/vault/sdk/database/dbplugin/v5" ) func main() { @@ -20,12 +20,8 @@ func main() { func Run() error { var f func() (interface{}, error) f = mysql.New(mysql.DefaultUserNameTemplate) - dbType, err := f() - if err != nil { - return err - } - dbplugin.Serve(dbType.(dbplugin.Database)) + dbplugin.ServeMultiplex(f) return nil } diff --git a/plugins/database/postgresql/postgresql-database-plugin/main.go b/plugins/database/postgresql/postgresql-database-plugin/main.go index 3d2e14cd9..75b5fd9ba 100644 --- a/plugins/database/postgresql/postgresql-database-plugin/main.go +++ b/plugins/database/postgresql/postgresql-database-plugin/main.go @@ -5,7 +5,7 @@ import ( "os" "github.com/hashicorp/vault/plugins/database/postgresql" - dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" + "github.com/hashicorp/vault/sdk/database/dbplugin/v5" ) func main() { @@ -18,12 +18,7 @@ func main() { // Run instantiates a PostgreSQL object, and runs the RPC server for the plugin func Run() error { - dbType, err := postgresql.New() - if err != nil { - return err - } - - dbplugin.Serve(dbType.(dbplugin.Database)) + dbplugin.ServeMultiplex(postgresql.New) return nil } diff --git a/plugins/database/redshift/redshift-database-plugin/main.go b/plugins/database/redshift/redshift-database-plugin/main.go index 35a4642fa..8d2f796ee 100644 --- a/plugins/database/redshift/redshift-database-plugin/main.go +++ b/plugins/database/redshift/redshift-database-plugin/main.go @@ -4,30 +4,20 @@ import ( "log" "os" - "github.com/hashicorp/vault/api" "github.com/hashicorp/vault/plugins/database/redshift" - "github.com/hashicorp/vault/sdk/database/dbplugin" + "github.com/hashicorp/vault/sdk/database/dbplugin/v5" ) func main() { - apiClientMeta := &api.PluginAPIClientMeta{} - flags := apiClientMeta.FlagSet() - flags.Parse(os.Args[1:]) - - if err := Run(apiClientMeta.GetTLSConfig()); err != nil { + if err := Run(); err != nil { log.Println(err) os.Exit(1) } } // Run instantiates a RedShift object, and runs the RPC server for the plugin -func Run(apiTLSConfig *api.TLSConfig) error { - dbType, err := redshift.New() - if err != nil { - return err - } - - dbplugin.Serve(dbType.(dbplugin.Database), api.VaultPluginTLSProvider(apiTLSConfig)) +func Run() error { + dbplugin.ServeMultiplex(redshift.New) return nil }