diff --git a/pkg/config/binder/binder.go b/pkg/config/binder/binder.go index 28f6e11c25..e59b210318 100644 --- a/pkg/config/binder/binder.go +++ b/pkg/config/binder/binder.go @@ -16,7 +16,7 @@ import ( // decoderConfigTagName sets the tag name to be used from the config structs // currently we only support "yaml" because we only support config loading // from yaml files and the yaml parser has no simple way to set a custom tag name to use -var decoderConfigTagName = "yaml" +const decoderConfigTagName = "yaml" // BindSourcesToStructs assigns any config value from a config file / env variable to struct `dst`. func BindSourcesToStructs(service string, dst any) error { @@ -42,6 +42,8 @@ func BindSourcesToStructsFS(fileSystem fs.FS, filePath, service string, dst any) return err } + // the error is ignored on purpose, matching the pre-extraction behavior: + // an unparseable yaml file binds nothing instead of failing the startup _ = cnf.LoadSources("yaml", yamlContent) err = cnf.BindStruct("", &dst) diff --git a/pkg/config/binder/binder_test.go b/pkg/config/binder/binder_test.go index e55c5d749b..07f76bc577 100644 --- a/pkg/config/binder/binder_test.go +++ b/pkg/config/binder/binder_test.go @@ -14,11 +14,13 @@ type TestConfig struct { } func TestBindSourcesToStructs(t *testing.T) { - // setup test env + // setup test env: one var set to pin env expansion, two deliberately + // unset to pin the defaults + t.Setenv("BINDER_TEST_SET_VAR", "from-env") yaml := ` -a: "${FOO_VAR|no-foo}" -b: "${BAR_VAR|no-bar}" -c: "${CODE_VAR|code}" +a: "${BINDER_TEST_SET_VAR|no-foo}" +b: "${BINDER_TEST_UNSET_VAR|no-bar}" +c: "${BINDER_TEST_OTHER_UNSET_VAR|code}" ` filePath := "etc/opencloud/foo.yaml" fs := fstest.MapFS{ @@ -31,7 +33,7 @@ c: "${CODE_VAR|code}" t.Error(err) } - assert.Equal(t, c.A, "no-foo") + assert.Equal(t, c.A, "from-env") assert.Equal(t, c.B, "no-bar") assert.Equal(t, c.C, "code") } diff --git a/pkg/config/helpers.go b/pkg/config/helpers.go index 7a7fbcf031..576ecab5ee 100644 --- a/pkg/config/helpers.go +++ b/pkg/config/helpers.go @@ -7,8 +7,10 @@ import ( ) // BindSourcesToStructs assigns any config value from a config file / env variable to struct `dst`. -// Backward-compatible re-export; the implementation lives in pkg/config/binder. -var BindSourcesToStructs = binder.BindSourcesToStructs +// The implementation lives in pkg/config/binder. +func BindSourcesToStructs(service string, dst any) error { + return binder.BindSourcesToStructs(service, dst) +} // LocalEndpoint returns the local endpoint for a given protocol and address. // Use it when configuring the reva runtime to get a service endpoint in the same