Files
steampipe/pkg/steampipeconfig/options/database.go
Binaek Sarkar 299697ae2f Updates in cache configuration to allow disabling of all caching on server. Closes #3258
STEAMPIPE_CACHE environment variable resolves to service cache enabled as well as client cache enabled

service cache enabled is used by the plugin manager to enable/disable caching on the plugins during startup (runtime toggle is not allowed) - with a max_ttl

client cache enabled is used to enable/disable the cache on the database connection (fdw)
A TTL can also be set on the client side capped to max_ttl on the server
2023-03-31 15:12:25 +01:00

138 lines
3.5 KiB
Go

package options
import (
"fmt"
"strings"
"github.com/turbot/steampipe/pkg/constants"
)
// Database
type Database struct {
Port *int `hcl:"port"`
Listen *string `hcl:"listen"`
SearchPath *string `hcl:"search_path"`
StartTimeout *int `hcl:"start_timeout"`
SearchPathPrefix *string `hcl:"search_path_prefix"`
Cache *bool `hcl:"cache"`
CacheMaxTtl *int `hcl:"cache_max_ttl"`
CacheMaxSizeMb *int `hcl:"cache_max_size_mb"`
}
// ConfigMap creates a config map that can be merged with viper
func (d *Database) ConfigMap() map[string]interface{} {
// only add keys which are non null
res := map[string]interface{}{}
if d.Port != nil {
res[constants.ArgDatabasePort] = d.Port
}
if d.Listen != nil {
res[constants.ArgListenAddress] = d.Listen
}
if d.SearchPath != nil {
// convert from string to array
res[constants.ArgSearchPath] = searchPathToArray(*d.SearchPath)
}
if d.StartTimeout != nil {
res[constants.ArgDatabaseStartTimeout] = d.StartTimeout
} else {
res[constants.ArgDatabaseStartTimeout] = constants.DBStartTimeout.Seconds()
}
if d.SearchPathPrefix != nil {
// convert from string to array
res[constants.ArgSearchPathPrefix] = searchPathToArray(*d.SearchPathPrefix)
}
if d.Cache != nil {
res[constants.ArgServiceCacheEnabled] = d.Cache
}
if d.CacheMaxTtl != nil {
res[constants.ArgCacheMaxTtl] = d.CacheMaxTtl
}
if d.CacheMaxSizeMb != nil {
res[constants.ArgMaxCacheSizeMb] = d.CacheMaxSizeMb
}
return res
}
// Merge :: merge other options over the the top of this options object
// i.e. if a property is set in otherOptions, it takes precedence
func (d *Database) Merge(otherOptions Options) {
switch o := otherOptions.(type) {
case *Database:
if o.Port != nil {
d.Port = o.Port
}
if o.Listen != nil {
d.Listen = o.Listen
}
if o.SearchPath != nil {
d.SearchPath = o.SearchPath
}
if o.StartTimeout != nil {
d.StartTimeout = o.StartTimeout
}
if o.SearchPathPrefix != nil {
d.SearchPathPrefix = o.SearchPathPrefix
}
if o.Cache != nil {
d.Cache = o.Cache
}
if o.CacheMaxSizeMb != nil {
d.CacheMaxSizeMb = o.CacheMaxSizeMb
}
if o.CacheMaxTtl != nil {
d.CacheMaxTtl = o.CacheMaxTtl
}
}
}
func (d *Database) String() string {
if d == nil {
return ""
}
var str []string
if d.Port == nil {
str = append(str, " Port: nil")
} else {
str = append(str, fmt.Sprintf(" Port: %d", *d.Port))
}
if d.Listen == nil {
str = append(str, " Listen: nil")
} else {
str = append(str, fmt.Sprintf(" Listen: %s", *d.Listen))
}
if d.SearchPath == nil {
str = append(str, " SearchPath: nil")
} else {
str = append(str, fmt.Sprintf(" SearchPath: %s", *d.SearchPath))
}
if d.StartTimeout == nil {
str = append(str, " ServiceStartTimeout: nil")
} else {
str = append(str, fmt.Sprintf(" ServiceStartTimeout: %d", *d.StartTimeout))
}
if d.SearchPathPrefix == nil {
str = append(str, " SearchPathPrefix: nil")
} else {
str = append(str, fmt.Sprintf(" SearchPathPrefix: %s", *d.SearchPathPrefix))
}
if d.Cache == nil {
str = append(str, " Cache: nil")
} else {
str = append(str, fmt.Sprintf(" Cache: %t", *d.Cache))
}
if d.CacheMaxSizeMb == nil {
str = append(str, " CacheMaxSizeMb: nil")
} else {
str = append(str, fmt.Sprintf(" CacheMaxSizeMb: %d", *d.CacheMaxSizeMb))
}
if d.CacheMaxTtl == nil {
str = append(str, " CacheMaxTtl: nil")
} else {
str = append(str, fmt.Sprintf(" CacheMaxTtl: %d", *d.CacheMaxTtl))
}
return strings.Join(str, "\n")
}