@@ -20,7 +20,6 @@ import (
2020 "github.com/turbot/steampipe/pkg/filepaths"
2121 "github.com/turbot/steampipe/pkg/steampipeconfig"
2222 "github.com/turbot/steampipe/pkg/steampipeconfig/modconfig"
23- "github.com/turbot/steampipe/pluginmanager"
2423 "go.opentelemetry.io/otel/attribute"
2524 "go.opentelemetry.io/otel/metric/global"
2625 "go.opentelemetry.io/otel/metric/instrument"
@@ -33,8 +32,7 @@ const (
3332
3433// Hub is a structure representing plugin hub
3534type Hub struct {
36- connections * connectionFactory
37- steampipeConfig * steampipeconfig.SteampipeConfig
35+ connections * connectionFactory
3836 runningIterators []Iterator
3937
4038 // if the cache is enabled/disabled by a metacommand, this will be non null
@@ -296,7 +294,7 @@ func (h *Hub) Scan(columns []string, quals *proto.Quals, limit int64, opts types
296294 // create a span for this scan
297295 scanTraceCtx := h .traceContextForScan (table , columns , limit , qualMap , connectionName )
298296
299- connectionConfig , _ := h . steampipeConfig .Connections [connectionName ]
297+ connectionConfig , _ := steampipeconfig . GlobalConfig .Connections [connectionName ]
300298
301299 var iterator Iterator
302300 // if this is an aggregate connection, create a group iterator
@@ -328,8 +326,8 @@ func (h *Hub) LoadConnectionConfig() (bool, error) {
328326 return false , err
329327 }
330328
331- configChanged := h . steampipeConfig == connectionConfig
332- h . steampipeConfig = connectionConfig
329+ configChanged := steampipeconfig . GlobalConfig == connectionConfig
330+ steampipeconfig . GlobalConfig = connectionConfig
333331
334332 return configChanged , nil
335333}
@@ -410,7 +408,7 @@ func (h *Hub) GetPathKeys(opts types.Options) ([]types.PathKey, error) {
410408 if err != nil {
411409 return nil , err
412410 }
413- schema := connectionPlugin .Schema .Schema [table ]
411+ schema := connectionPlugin .ConnectionMap [ connectionName ]. Schema .Schema [table ]
414412 var allColumns = make ([]string , len (schema .Columns ))
415413 for i , c := range schema .Columns {
416414 allColumns [i ] = c .Name
@@ -484,7 +482,7 @@ func (h *Hub) startScanForConnection(connectionName string, table string, qualMa
484482 // determine whether to include the limit, based on the quals
485483 // we ONLY pushgdown the limit is all quals have corresponding key columns,
486484 // and if the qual operator is supported by the key column
487- if limit != - 1 && ! h .shouldPushdownLimit (table , qualMap , connectionPlugin ) {
485+ if limit != - 1 && ! h .shouldPushdownLimit (table , qualMap , connectionName , connectionPlugin ) {
488486 limit = - 1
489487 }
490488
@@ -499,7 +497,7 @@ func (h *Hub) startScanForConnection(connectionName string, table string, qualMa
499497 // cache not enabled - create a scan iterator
500498 log .Printf ("[TRACE] startScanForConnection creating a new scan iterator" )
501499 queryContext := proto .NewQueryContext (columns , qualMap , limit )
502- iterator := newScanIterator (h , connectionPlugin , table , qualMap , columns , limit , scanTraceCtx )
500+ iterator := newScanIterator (h , connectionPlugin , connectionName , table , qualMap , columns , limit , scanTraceCtx )
503501
504502 if err := h .startScan (iterator , queryContext , scanTraceCtx ); err != nil {
505503 return nil , err
@@ -511,9 +509,9 @@ func (h *Hub) startScanForConnection(connectionName string, table string, qualMa
511509// determine whether to include the limit, based on the quals
512510// we ONLY pushdown the limit is all quals have corresponding key columns,
513511// and if the qual operator is supported by the key column
514- func (h * Hub ) shouldPushdownLimit (table string , qualMap map [string ]* proto.Quals , connectionPlugin * steampipeconfig.ConnectionPlugin ) bool {
512+ func (h * Hub ) shouldPushdownLimit (table string , qualMap map [string ]* proto.Quals , connectionName string , connectionPlugin * steampipeconfig.ConnectionPlugin ) bool {
515513 // build a map of all key columns
516- tableSchema , ok := connectionPlugin .Schema .Schema [table ]
514+ tableSchema , ok := connectionPlugin .ConnectionMap [ connectionName ]. Schema .Schema [table ]
517515 if ! ok {
518516 // any errors, just default to NOT pushing down the limit
519517 return false
@@ -561,24 +559,24 @@ func (h *Hub) startScan(iterator *scanIterator, queryContext *proto.QueryContext
561559 h .throttle ()
562560
563561 table := iterator .table
564- c := iterator .connection
565-
566- callId := grpc .BuildCallId (c . ConnectionName )
562+ connectionPlugin := iterator .connectionPlugin
563+ connectionName := iterator . connectionName
564+ callId := grpc .BuildCallId (connectionName )
567565
568566 req := & proto.ExecuteRequest {
569567 Table : table ,
570568 QueryContext : queryContext ,
571- Connection : c . ConnectionName ,
572- CacheEnabled : h .cacheEnabled (c ),
573- CacheTtl : int64 (h .cacheTTL (c . ConnectionName ).Seconds ()),
569+ Connection : connectionName ,
570+ CacheEnabled : h .cacheEnabled (connectionName ),
571+ CacheTtl : int64 (h .cacheTTL (connectionName ).Seconds ()),
574572 CallId : callId ,
575573 TraceContext : grpc .CreateCarrierFromContext (traceCtx .Ctx ),
576574 }
577575
578576 log .Printf ("[INFO] StartScan for table: %s, callId %s, cache enabled: %v, iterator %p" , table , callId , req .CacheEnabled , iterator )
579- stream , ctx , cancel , err := c .PluginClient .Execute (req )
577+ stream , ctx , cancel , err := connectionPlugin .PluginClient .Execute (req )
580578 // format GRPC errors and ignore not implemented errors for backwards compatibility
581- err = grpc .HandleGrpcError (err , c .PluginName , "Execute" )
579+ err = grpc .HandleGrpcError (err , connectionPlugin .PluginName , "Execute" )
582580 if err != nil {
583581 log .Printf ("[WARN] startScan: plugin Execute function callId: %s returned error: %v\n " , callId , err )
584582 iterator .setError (err )
@@ -595,7 +593,7 @@ func (h *Hub) getConnectionPlugin(connectionName string) (*steampipeconfig.Conne
595593 log .Printf ("[TRACE] hub.getConnectionPlugin for connection '%s`" , connectionName )
596594
597595 // get the plugin FQN
598- connectionConfig , ok := h . steampipeConfig .Connections [connectionName ]
596+ connectionConfig , ok := steampipeconfig . GlobalConfig .Connections [connectionName ]
599597 if ! ok {
600598 return nil , fmt .Errorf ("no connection config loaded for connection '%s'" , connectionName )
601599 }
@@ -610,49 +608,25 @@ func (h *Hub) getConnectionPlugin(connectionName string) (*steampipeconfig.Conne
610608 return c , nil
611609}
612610
613- // load the given plugin connection into the connection map and return the schema
614- func (h * Hub ) createConnectionPlugin (pluginFQN , connectionName string ) (* steampipeconfig.ConnectionPlugin , error ) {
615- // load the config for this connection
616- connection , ok := h .steampipeConfig .Connections [connectionName ]
617- if ! ok {
618- log .Printf ("[WARN] no config found for connection %s" , connectionName )
619- return nil , fmt .Errorf ("no config found for connection %s" , connectionName )
620- }
621-
622- log .Printf ("[TRACE] createConnectionPlugin plugin %s, connection %s, config: %s\n " , pluginmanager .PluginFQNToSchemaName (pluginFQN ), connectionName , connection .Config )
623-
624- connectionPlugins , res := steampipeconfig .CreateConnectionPlugins ([]* modconfig.Connection {connection })
625- if res .Error != nil {
626- return nil , res .Error
627- }
628- if connectionPlugins [connection .Name ] == nil {
629- if len (res .Warnings ) > 0 {
630- return nil , fmt .Errorf ("%s" , strings .Join (res .Warnings , "," ))
631- }
632- return nil , fmt .Errorf ("unknown failure" )
633- }
634- return connectionPlugins [connection .Name ], nil
635- }
636-
637- func (h * Hub ) cacheEnabled (connection * steampipeconfig.ConnectionPlugin ) bool {
611+ func (h * Hub ) cacheEnabled (connectionName string ) bool {
638612 if h .overrideCacheEnabled != nil {
639613 res := * h .overrideCacheEnabled
640614 log .Printf ("[TRACE] cacheEnabled overrideCacheEnabled %v" , * h .overrideCacheEnabled )
641615 return res
642616 }
643617 // ask the steampipe config for resolved plugin options - this will use default values where needed
644- connectionOptions := h . steampipeConfig .GetConnectionOptions (connection . ConnectionName )
618+ connectionOptions := steampipeconfig . GlobalConfig .GetConnectionOptions (connectionName )
645619
646620 // the config loading code should ALWAYS populate the connection options, using defaults if needed
647621 if connectionOptions .Cache == nil {
648- panic (fmt .Sprintf ("No cache options found for connection %s" , connection ))
622+ panic (fmt .Sprintf ("No cache options found for connection %s" , connectionName ))
649623 }
650624 return * connectionOptions .Cache
651625}
652626
653627func (h * Hub ) cacheTTL (connectionName string ) time.Duration {
654628 // ask the steampipe config for resolved plugin options - this will use default values where needed
655- connectionOptions := h . steampipeConfig .GetConnectionOptions (connectionName )
629+ connectionOptions := steampipeconfig . GlobalConfig .GetConnectionOptions (connectionName )
656630
657631 // the config loading code shouls ALWAYS populate the connection options, using defaults if needed
658632 if connectionOptions .CacheTTL == nil {
@@ -671,7 +645,7 @@ func (h *Hub) cacheTTL(connectionName string) time.Duration {
671645
672646// IsAggregatorConnection returns whether the connection with the given name is of type "aggregate"
673647func (h * Hub ) IsAggregatorConnection (connectionName string ) bool {
674- connectionConfig , ok := h . steampipeConfig .Connections [connectionName ]
648+ connectionConfig , ok := steampipeconfig . GlobalConfig .Connections [connectionName ]
675649 return ok && connectionConfig .Type == modconfig .ConnectionTypeAggregator
676650}
677651
@@ -680,7 +654,7 @@ func (h *Hub) GetAggregateConnectionChild(connectionName string) string {
680654 if ! h .IsAggregatorConnection (connectionName ) {
681655 panic (fmt .Sprintf ("GetAggregateConnectionChild called for connection %s which is not an aggregate" , connectionName ))
682656 }
683- aggregateConnection := h . steampipeConfig .Connections [connectionName ]
657+ aggregateConnection := steampipeconfig . GlobalConfig .Connections [connectionName ]
684658 // get first child
685659 return aggregateConnection .FirstChild ().Name
686660}
0 commit comments