Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare multiplexing support for database plugins #16995

Merged
merged 3 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
```
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"
vinay-gopalan marked this conversation as resolved.
Show resolved Hide resolved
)

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
}