From 31ef1818fc53f9a77dc19746cda229ed34edd6bc Mon Sep 17 00:00:00 2001 From: kaidaguerre Date: Fri, 12 Apr 2024 05:39:14 -0500 Subject: [PATCH] Implement getServerCacheEnabled separately for local and remote hub - do not access steampipeconfig.GlobalConfig for local hub (as it will not be populated. Closes #434 --- hub/hub_base.go | 20 -------------------- hub/hub_local.go | 15 +++++++++++++++ hub/hub_remote.go | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/hub/hub_base.go b/hub/hub_base.go index cefac945..ea983c5a 100644 --- a/hub/hub_base.go +++ b/hub/hub_base.go @@ -3,9 +3,7 @@ package hub import ( "context" "fmt" - typehelpers "github.com/turbot/go-kit/types" "log" - "os" "strings" "time" @@ -505,21 +503,3 @@ func (h *hubBase) cacheTTL(connectionName string) time.Duration { log.Printf("[INFO] cacheTTL 5") return ttl } - -// resolve the server cache enabled property -func (h *hubBase) getServerCacheEnabled() bool { - var res = true - if val, ok := os.LookupEnv(constants.EnvCacheEnabled); ok { - if boolVal, err := typehelpers.ToBool(val); err == nil { - res = boolVal - } - } - - if steampipeconfig.GlobalConfig.DatabaseOptions != nil && steampipeconfig.GlobalConfig.DatabaseOptions.Cache != nil { - res = *steampipeconfig.GlobalConfig.DatabaseOptions.Cache - } - - log.Printf("[INFO] Hub.getServerCacheEnabled returning %v", res) - - return res -} diff --git a/hub/hub_local.go b/hub/hub_local.go index 826e92ee..25f7fb36 100644 --- a/hub/hub_local.go +++ b/hub/hub_local.go @@ -5,6 +5,7 @@ import ( "os" "time" + typehelpers "github.com/turbot/go-kit/types" "github.com/turbot/steampipe-plugin-sdk/v5/grpc" "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" "github.com/turbot/steampipe-plugin-sdk/v5/logging" @@ -270,3 +271,17 @@ func (l *HubLocal) cacheTTL(s string) time.Duration { } return 10 * time.Hour } + +// resolve the server cache enabled property +func (l *HubLocal) getServerCacheEnabled() bool { + var res = true + if val, ok := os.LookupEnv(constants.EnvCacheEnabled); ok { + if boolVal, err := typehelpers.ToBool(val); err == nil { + res = boolVal + } + } + + log.Printf("[INFO] Hub.getServerCacheEnabled returning %v", res) + + return res +} diff --git a/hub/hub_remote.go b/hub/hub_remote.go index 41930865..1e0c088b 100644 --- a/hub/hub_remote.go +++ b/hub/hub_remote.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + typehelpers "github.com/turbot/go-kit/types" "github.com/turbot/steampipe-plugin-sdk/v5/grpc" "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" "github.com/turbot/steampipe-plugin-sdk/v5/logging" @@ -322,3 +323,21 @@ func (h *RemoteHub) cacheTTL(connectionName string) time.Duration { } return ttl } + +// resolve the server cache enabled property +func (h *RemoteHub) getServerCacheEnabled() bool { + var res = true + if val, ok := os.LookupEnv(constants.EnvCacheEnabled); ok { + if boolVal, err := typehelpers.ToBool(val); err == nil { + res = boolVal + } + } + + if steampipeconfig.GlobalConfig.DatabaseOptions != nil && steampipeconfig.GlobalConfig.DatabaseOptions.Cache != nil { + res = *steampipeconfig.GlobalConfig.DatabaseOptions.Cache + } + + log.Printf("[INFO] Hub.getServerCacheEnabled returning %v", res) + + return res +}