From 33ede0f106c08c62cf6de416c932f1094fef99a0 Mon Sep 17 00:00:00 2001 From: Ben Brooks Date: Thu, 5 Oct 2023 17:55:18 +0100 Subject: [PATCH] Flip bool (default to true) --- rest/config_flags.go | 2 +- rest/config_startup.go | 15 ++++++++------- rest/config_test.go | 40 +++++++++++++++++++-------------------- rest/handler.go | 2 +- rest/utilities_testing.go | 4 ++-- 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/rest/config_flags.go b/rest/config_flags.go index 846015acc8..1b1b3594c3 100644 --- a/rest/config_flags.go +++ b/rest/config_flags.go @@ -132,7 +132,7 @@ func registerConfigFlags(config *StartupConfig, fs *flag.FlagSet) map[string]con "unsupported.serverless.enabled": {&config.Unsupported.Serverless.Enabled, fs.Bool("unsupported.serverless.enabled", false, "Settings for running Sync Gateway in serverless mode.")}, "unsupported.serverless.min_config_fetch_interval": {&config.Unsupported.Serverless.MinConfigFetchInterval, fs.String("unsupported.serverless.min_config_fetch_interval", "", "How long to cache configs fetched from the buckets for. This cache is used for requested databases that SG does not know about.")}, "unsupported.use_xattr_config": {&config.Unsupported.UseXattrConfig, fs.Bool("unsupported.use_xattr_config", false, "Store database configurations in system xattrs")}, - "unsupported.disallow_dbconfig_env_vars": {&config.Unsupported.DisallowDbConfigEnvVars, fs.Bool("unsupported.disallow_dbconfig_env_vars", false, "Skips environment variable expansion in database configs")}, + "unsupported.allow_dbconfig_env_vars": {&config.Unsupported.AllowDbConfigEnvVars, fs.Bool("unsupported.allow_dbconfig_env_vars", true, "Can be set to false to skip environment variable expansion in database configs")}, "unsupported.user_queries": {&config.Unsupported.UserQueries, fs.Bool("unsupported.user_queries", false, "Whether user-query APIs are enabled")}, diff --git a/rest/config_startup.go b/rest/config_startup.go index 728d1f4832..e761ab05de 100644 --- a/rest/config_startup.go +++ b/rest/config_startup.go @@ -63,6 +63,7 @@ func DefaultStartupConfig(defaultLogFilePath string) StartupConfig { Enabled: base.BoolPtr(false), MinConfigFetchInterval: base.NewConfigDuration(DefaultMinConfigFetchInterval), }, + AllowDbConfigEnvVars: base.BoolPtr(true), }, MaxFileDescriptors: DefaultMaxFileDescriptors, } @@ -141,13 +142,13 @@ type ReplicatorConfig struct { } type UnsupportedConfig struct { - StatsLogFrequency *base.ConfigDuration `json:"stats_log_frequency,omitempty" help:"How often should stats be written to stats logs"` - UseStdlibJSON *bool `json:"use_stdlib_json,omitempty" help:"Bypass the jsoniter package and use Go's stdlib instead"` - Serverless ServerlessConfig `json:"serverless,omitempty"` - HTTP2 *HTTP2Config `json:"http2,omitempty"` - UserQueries *bool `json:"user_queries,omitempty" help:"Feature flag for user N1QL/JS/GraphQL queries"` - UseXattrConfig *bool `json:"use_xattr_config,omitempty" help:"Store database configurations in system xattrs"` - DisallowDbConfigEnvVars *bool `json:"disallow_dbconfig_env_vars,omitempty" help:"Skips environment variable expansion in database configs"` + StatsLogFrequency *base.ConfigDuration `json:"stats_log_frequency,omitempty" help:"How often should stats be written to stats logs"` + UseStdlibJSON *bool `json:"use_stdlib_json,omitempty" help:"Bypass the jsoniter package and use Go's stdlib instead"` + Serverless ServerlessConfig `json:"serverless,omitempty"` + HTTP2 *HTTP2Config `json:"http2,omitempty"` + UserQueries *bool `json:"user_queries,omitempty" help:"Feature flag for user N1QL/JS/GraphQL queries"` + UseXattrConfig *bool `json:"use_xattr_config,omitempty" help:"Store database configurations in system xattrs"` + AllowDbConfigEnvVars *bool `json:"allow_dbconfig_env_vars,omitempty" help:"Can be set to false to skip environment variable expansion in database configs"` } type ServerlessConfig struct { diff --git a/rest/config_test.go b/rest/config_test.go index 1061b88911..64c902562a 100644 --- a/rest/config_test.go +++ b/rest/config_test.go @@ -1306,7 +1306,7 @@ func TestExpandEnv(t *testing.T) { } } -// TestDbConfigEnvVarsToggle ensures that DisallowDbConfigEnvVars toggles the ability to use env vars in db config. +// TestDbConfigEnvVarsToggle ensures that AllowDbConfigEnvVars toggles the ability to use env vars in db config. func TestDbConfigEnvVarsToggle(t *testing.T) { // Set up an env var with a secret value and use it as a channel name to assert its value. const ( @@ -1318,36 +1318,36 @@ func TestDbConfigEnvVarsToggle(t *testing.T) { unexpandedVal := fmt.Sprintf("${%s:-%s}", varName, defaultVal) tests := []struct { - disallowDbConfigEnvVars bool - setEnvVar bool - expectedChannel string - unexpectedChannels []string + allowDbConfigEnvVars *bool + setEnvVar bool + expectedChannel string + unexpectedChannels []string }{ { - disallowDbConfigEnvVars: false, - setEnvVar: true, - expectedChannel: secretVal, - unexpectedChannels: []string{defaultVal, unexpandedVal}, + allowDbConfigEnvVars: nil, // defaults to true - so use nil to check default handling + setEnvVar: true, + expectedChannel: secretVal, + unexpectedChannels: []string{defaultVal, unexpandedVal}, }, { - disallowDbConfigEnvVars: false, - setEnvVar: false, - expectedChannel: defaultVal, - unexpectedChannels: []string{secretVal, unexpandedVal}, + allowDbConfigEnvVars: base.BoolPtr(true), + setEnvVar: false, + expectedChannel: defaultVal, + unexpectedChannels: []string{secretVal, unexpandedVal}, }, { - disallowDbConfigEnvVars: true, - setEnvVar: true, - expectedChannel: unexpandedVal, - unexpectedChannels: []string{secretVal, defaultVal}, + allowDbConfigEnvVars: base.BoolPtr(false), + setEnvVar: true, + expectedChannel: unexpandedVal, + unexpectedChannels: []string{secretVal, defaultVal}, }, } for _, test := range tests { - t.Run(fmt.Sprintf("disallowDbConfigEnvVars=%v_setEnvVar=%v", test.disallowDbConfigEnvVars, test.setEnvVar), func(t *testing.T) { + t.Run(fmt.Sprintf("allowDbConfigEnvVars=%v_setEnvVar=%v", test.allowDbConfigEnvVars, test.setEnvVar), func(t *testing.T) { rt := NewRestTesterDefaultCollection(t, &RestTesterConfig{ - PersistentConfig: true, - disallowDbConfigEnvVars: test.disallowDbConfigEnvVars, + PersistentConfig: true, + allowDbConfigEnvVars: test.allowDbConfigEnvVars, }) defer rt.Close() diff --git a/rest/handler.go b/rest/handler.go index 398e53eac4..99166b30e0 100644 --- a/rest/handler.go +++ b/rest/handler.go @@ -1109,7 +1109,7 @@ func (h *handler) readSanitizeJSON(val interface{}) error { } // Expand environment variables. - if !base.BoolDefault(h.server.Config.Unsupported.DisallowDbConfigEnvVars, false) { + if base.BoolDefault(h.server.Config.Unsupported.AllowDbConfigEnvVars, true) { content, err = expandEnv(h.ctx(), content) if err != nil { return err diff --git a/rest/utilities_testing.go b/rest/utilities_testing.go index db81c67bab..0d0ab88f79 100644 --- a/rest/utilities_testing.go +++ b/rest/utilities_testing.go @@ -70,7 +70,7 @@ type RestTesterConfig struct { serverless bool // Runs SG in serverless mode. Must be used in conjunction with persistent config collectionConfig collectionConfiguration numCollections int - disallowDbConfigEnvVars bool + allowDbConfigEnvVars *bool } type collectionConfiguration uint8 @@ -216,7 +216,7 @@ func (rt *RestTester) Bucket() base.Bucket { sc.Bootstrap.UseTLSServer = &rt.RestTesterConfig.useTLSServer sc.Bootstrap.ServerTLSSkipVerify = base.BoolPtr(base.TestTLSSkipVerify()) sc.Unsupported.Serverless.Enabled = &rt.serverless - sc.Unsupported.DisallowDbConfigEnvVars = &rt.RestTesterConfig.disallowDbConfigEnvVars + sc.Unsupported.AllowDbConfigEnvVars = rt.RestTesterConfig.allowDbConfigEnvVars if rt.serverless { if !rt.PersistentConfig { rt.TB.Fatalf("Persistent config must be used when running in serverless mode")