From 1a88a3ab72e09bf2e9f652c01fa8022902e72ea4 Mon Sep 17 00:00:00 2001 From: kaidaguerre Date: Tue, 1 Feb 2022 20:23:27 +0000 Subject: [PATCH] Update CreateConnectionPlugins to use options to determine whether to set connection config. Closes #1368 --- steampipeconfig/connection_plugin.go | 30 ++++++++++++++++----------- steampipeconfig/connection_updates.go | 4 ++-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/steampipeconfig/connection_plugin.go b/steampipeconfig/connection_plugin.go index 8f9711b99..c3e68c3a0 100644 --- a/steampipeconfig/connection_plugin.go +++ b/steampipeconfig/connection_plugin.go @@ -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() diff --git a/steampipeconfig/connection_updates.go b/steampipeconfig/connection_updates.go index 18d8b9856..029e2d74d 100644 --- a/steampipeconfig/connection_updates.go +++ b/steampipeconfig/connection_updates.go @@ -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 }