Skip to content

Commit

Permalink
Prepare multiplexing support for database plugins (#16995)
Browse files Browse the repository at this point in the history
* prepare multiplexing support for database plugins
  • Loading branch information
maxcoulombe authored Sep 6, 2022
1 parent 41f78c6 commit 59114c5
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 62 deletions.
3 changes: 3 additions & 0 deletions changelog/16995.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
plugins/multiplexing: Added multiplexing support to database plugins if run as external plugins
```
9 changes: 2 additions & 7 deletions plugins/database/cassandra/cassandra-database-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
9 changes: 2 additions & 7 deletions plugins/database/hana/hana-database-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
9 changes: 2 additions & 7 deletions plugins/database/influxdb/influxdb-database-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
9 changes: 2 additions & 7 deletions plugins/database/mongodb/mongodb-database-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
9 changes: 2 additions & 7 deletions plugins/database/mssql/mssql-database-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
8 changes: 2 additions & 6 deletions plugins/database/mysql/mysql-database-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
18 changes: 4 additions & 14 deletions plugins/database/redshift/redshift-database-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 59114c5

Please sign in to comment.