Skip to content

Commit

Permalink
Flip bool (default to true)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrks committed Oct 5, 2023
1 parent db4ae00 commit 33ede0f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion rest/config_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")},

Expand Down
15 changes: 8 additions & 7 deletions rest/config_startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func DefaultStartupConfig(defaultLogFilePath string) StartupConfig {
Enabled: base.BoolPtr(false),
MinConfigFetchInterval: base.NewConfigDuration(DefaultMinConfigFetchInterval),
},
AllowDbConfigEnvVars: base.BoolPtr(true),
},
MaxFileDescriptors: DefaultMaxFileDescriptors,
}
Expand Down Expand Up @@ -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 {
Expand Down
40 changes: 20 additions & 20 deletions rest/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion rest/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions rest/utilities_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 33ede0f

Please sign in to comment.