mirror of
https://github.com/turbot/steampipe.git
synced 2026-04-13 22:00:05 -04:00
Update CreateConnectionPlugins to use options to determine whether to set connection config. Closes #1368
This commit is contained in:
@@ -20,6 +20,10 @@ import (
|
||||
"github.com/turbot/steampipe/utils"
|
||||
)
|
||||
|
||||
type CreateConnectionPluginOptions struct {
|
||||
SetConnectionConfig bool
|
||||
}
|
||||
|
||||
// ConnectionPlugin is a structure representing an instance of a plugin
|
||||
// NOTE: this corresponds to a single steampipe connection,
|
||||
// i.e. we have 1 plugin instance per steampipe connection
|
||||
@@ -34,7 +38,7 @@ type ConnectionPlugin struct {
|
||||
}
|
||||
|
||||
// CreateConnectionPlugins instantiates plugins for specified connections, fetches schemas and sends connection config
|
||||
func CreateConnectionPlugins(connections ...*modconfig.Connection) (connectionPluginMap map[string]*ConnectionPlugin, res *RefreshConnectionResult) {
|
||||
func CreateConnectionPlugins(connections []*modconfig.Connection, opts *CreateConnectionPluginOptions) (connectionPluginMap map[string]*ConnectionPlugin, res *RefreshConnectionResult) {
|
||||
res = &RefreshConnectionResult{}
|
||||
log.Printf("[TRACE] CreateConnectionPlugin creating %d connections", len(connections))
|
||||
|
||||
@@ -62,7 +66,7 @@ func CreateConnectionPlugins(connections ...*modconfig.Connection) (connectionPl
|
||||
|
||||
// now create a connection plugin for each connection
|
||||
for _, connection := range connections {
|
||||
connectionPlugin, err := createConnectionPlugin(connection, getResponse)
|
||||
connectionPlugin, err := createConnectionPlugin(connection, getResponse, opts)
|
||||
if err != nil {
|
||||
res.AddWarning(fmt.Sprintf("failed to start plugin '%s': %s", connection.PluginShortName, err))
|
||||
continue
|
||||
@@ -145,7 +149,7 @@ func buildSchemaModeMap(connectionPluginMap map[string]*ConnectionPlugin, plugin
|
||||
return schemaModeMap
|
||||
}
|
||||
|
||||
func createConnectionPlugin(connection *modconfig.Connection, getResponse *proto.GetResponse) (*ConnectionPlugin, error) {
|
||||
func createConnectionPlugin(connection *modconfig.Connection, getResponse *proto.GetResponse, opts *CreateConnectionPluginOptions) (*ConnectionPlugin, error) {
|
||||
pluginName := connection.Plugin
|
||||
connectionName := connection.Name
|
||||
connectionConfig := connection.Config
|
||||
@@ -167,16 +171,18 @@ func createConnectionPlugin(connection *modconfig.Connection, getResponse *proto
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// set the connection config
|
||||
req := &sdkproto.SetConnectionConfigRequest{
|
||||
ConnectionName: connectionName,
|
||||
ConnectionConfig: connectionConfig,
|
||||
}
|
||||
if opts.SetConnectionConfig {
|
||||
// set the connection config
|
||||
req := &sdkproto.SetConnectionConfigRequest{
|
||||
ConnectionName: connectionName,
|
||||
ConnectionConfig: connectionConfig,
|
||||
}
|
||||
|
||||
if err = pluginClient.SetConnectionConfig(req); err != nil {
|
||||
log.Printf("[TRACE] failed to set connection config for connection '%s' - pid %d: %s",
|
||||
connectionName, reattach.Pid, err)
|
||||
return nil, err
|
||||
if err = pluginClient.SetConnectionConfig(req); err != nil {
|
||||
log.Printf("[TRACE] failed to set connection config for connection '%s' - pid %d: %s",
|
||||
connectionName, reattach.Pid, err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
// fetch the supported operations
|
||||
supportedOperations, err := pluginClient.GetSupportedOperations()
|
||||
|
||||
@@ -141,7 +141,7 @@ func (u *ConnectionUpdates) populateConnectionPlugins(alreadyCreatedConnectionPl
|
||||
// - remove these from list of plugins to create
|
||||
connectionsToCreate := removeConnectionsFromList(updateConnections, alreadyCreatedConnectionPlugins)
|
||||
// now create them
|
||||
connectionPlugins, res := CreateConnectionPlugins(connectionsToCreate...)
|
||||
connectionPlugins, res := CreateConnectionPlugins(connectionsToCreate, &CreateConnectionPluginOptions{SetConnectionConfig: true})
|
||||
if res.Error != nil {
|
||||
return res
|
||||
}
|
||||
@@ -188,7 +188,7 @@ func getSchemaHashesForDynamicSchemas(requiredConnectionData ConnectionDataMap,
|
||||
}
|
||||
}
|
||||
|
||||
connectionsPluginsWithDynamicSchema, res := CreateConnectionPlugins(connectionsWithDynamicSchema.Connections()...)
|
||||
connectionsPluginsWithDynamicSchema, res := CreateConnectionPlugins(connectionsWithDynamicSchema.Connections(), &CreateConnectionPluginOptions{SetConnectionConfig: true})
|
||||
if res.Error != nil {
|
||||
return nil, nil, res.Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user