Skip to content

Commit

Permalink
Implement getServerCacheEnabled separately for local and remote hub -…
Browse files Browse the repository at this point in the history
… do not access steampipeconfig.GlobalConfig for local hub (as it will not be populated. Closes #434
  • Loading branch information
kaidaguerre authored Apr 12, 2024
1 parent 46b46ca commit 31ef181
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
20 changes: 0 additions & 20 deletions hub/hub_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package hub
import (
"context"
"fmt"
typehelpers "github.com/turbot/go-kit/types"
"log"
"os"
"strings"
"time"

Expand Down Expand Up @@ -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
}
15 changes: 15 additions & 0 deletions hub/hub_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
19 changes: 19 additions & 0 deletions hub/hub_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit 31ef181

Please sign in to comment.