mirror of
https://github.com/turbot/steampipe.git
synced 2026-02-17 01:00:09 -05:00
Fix ConnectionConfigMap.Diff inconsistent usage of Plugin and PluginInstance. Closes #3895 Fix GetConnectionStateErrorSql returning invalid query with additional parameter. Closes #3896 Update FDW to v1.8.0-rc.11 - fix failure to load connection config when importing schema
65 lines
2.4 KiB
Go
65 lines
2.4 KiB
Go
package connection
|
|
|
|
import (
|
|
typehelpers "github.com/turbot/go-kit/types"
|
|
sdkproto "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
|
|
"github.com/turbot/steampipe/pkg/steampipeconfig/modconfig"
|
|
)
|
|
|
|
type ConnectionConfigMap map[string]*sdkproto.ConnectionConfig
|
|
|
|
// NewConnectionConfigMap creates a map of sdkproto.ConnectionConfig keyed by connection name
|
|
// NOTE: connections in error are EXCLUDED
|
|
func NewConnectionConfigMap(connectionMap map[string]*modconfig.Connection) ConnectionConfigMap {
|
|
configMap := make(ConnectionConfigMap)
|
|
for k, v := range connectionMap {
|
|
if v.Error != nil {
|
|
continue
|
|
}
|
|
|
|
configMap[k] = &sdkproto.ConnectionConfig{
|
|
Connection: v.Name,
|
|
Plugin: v.Plugin,
|
|
PluginShortName: v.PluginAlias,
|
|
Config: v.Config,
|
|
ChildConnections: v.GetResolveConnectionNames(),
|
|
PluginInstance: typehelpers.SafeString(v.PluginInstance),
|
|
}
|
|
}
|
|
|
|
return configMap
|
|
}
|
|
|
|
func (m ConnectionConfigMap) Diff(otherMap ConnectionConfigMap) (addedConnections, deletedConnections, changedConnections map[string][]*sdkproto.ConnectionConfig) {
|
|
// results are maps of connections keyed by plugin instance
|
|
addedConnections = make(map[string][]*sdkproto.ConnectionConfig)
|
|
deletedConnections = make(map[string][]*sdkproto.ConnectionConfig)
|
|
changedConnections = make(map[string][]*sdkproto.ConnectionConfig)
|
|
|
|
for name, connection := range m {
|
|
if otherConnection, ok := otherMap[name]; !ok {
|
|
deletedConnections[connection.PluginInstance] = append(deletedConnections[connection.PluginInstance], connection)
|
|
} else {
|
|
// check for changes
|
|
|
|
// special case - if the plugin has changed, treat this as a deletion and a re-add
|
|
if connection.PluginInstance != otherConnection.PluginInstance {
|
|
addedConnections[otherConnection.PluginInstance] = append(addedConnections[otherConnection.PluginInstance], otherConnection)
|
|
deletedConnections[connection.PluginInstance] = append(deletedConnections[connection.PluginInstance], connection)
|
|
} else {
|
|
if !connection.Equals(otherConnection) {
|
|
changedConnections[connection.PluginInstance] = append(changedConnections[connection.PluginInstance], otherConnection)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for otherName, otherConnection := range otherMap {
|
|
if _, ok := m[otherName]; !ok {
|
|
addedConnections[otherConnection.PluginInstance] = append(addedConnections[otherConnection.PluginInstance], otherConnection)
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|