diff --git a/deployment/domain_config_getter.go b/deployment/domain_config_getter.go new file mode 100644 index 000000000..002ca6dbe --- /dev/null +++ b/deployment/domain_config_getter.go @@ -0,0 +1,14 @@ +package deployment + +import "os" + +// DomainConfigGetter retrieves config values by key. +type DomainConfigGetter interface { + Get(key string) (value string, found bool) +} + +type envVarDomainConfigGetter struct{} + +func (envVarDomainConfigGetter) Get(key string) (string, bool) { + return os.LookupEnv(key) +} diff --git a/deployment/domain_config_getter_test.go b/deployment/domain_config_getter_test.go new file mode 100644 index 000000000..2002092f2 --- /dev/null +++ b/deployment/domain_config_getter_test.go @@ -0,0 +1,31 @@ +package deployment + +import ( + "os" + "testing" + + "github.com/stretchr/testify/require" +) + +//nolint:paralleltest // Mutates process-global env vars via os.Setenv. +func TestEnvVarDomainConfigGetter_Get(t *testing.T) { + const ( + key = "CLDF_TEST_DOMAIN_CONFIG_GETTER_KEY" + value = "domain-config-value" + ) + + prevValue, hadPrevValue := os.LookupEnv(key) + require.NoError(t, os.Setenv(key, value)) + t.Cleanup(func() { + if hadPrevValue { + _ = os.Setenv(key, prevValue) + return + } + _ = os.Unsetenv(key) + }) + + var getter DomainConfigGetter = envVarDomainConfigGetter{} + got, found := getter.Get(key) + require.True(t, found) + require.Equal(t, value, got) +} diff --git a/deployment/environment.go b/deployment/environment.go index 8b05e82c1..e50eb8fa8 100644 --- a/deployment/environment.go +++ b/deployment/environment.go @@ -60,6 +60,8 @@ type Environment struct { OperationsBundle operations.Bundle // BlockChains is the container of all chains in the environment. BlockChains chain.BlockChains + // DomainConfigGetter is used to read domain-backed configuration values. + DomainConfigGetter DomainConfigGetter } // EnvironmentOption is a functional option for configuring an Environment @@ -88,8 +90,9 @@ func NewEnvironment( GetContext: ctx, OCRSecrets: secrets, // default to memory reporter as that is the only reporter available for now - OperationsBundle: operations.NewBundle(ctx, logger, operations.NewMemoryReporter()), - BlockChains: blockChains, + OperationsBundle: operations.NewBundle(ctx, logger, operations.NewMemoryReporter()), + BlockChains: blockChains, + DomainConfigGetter: envVarDomainConfigGetter{}, } // Apply functional options @@ -115,16 +118,17 @@ func (e Environment) Clone() Environment { } return Environment{ - Name: e.Name, - Logger: e.Logger, - ExistingAddresses: ab, - DataStore: ds.Seal(), - NodeIDs: e.NodeIDs, - Offchain: e.Offchain, - GetContext: e.GetContext, - OCRSecrets: e.OCRSecrets, - OperationsBundle: e.OperationsBundle, - BlockChains: e.BlockChains, + Name: e.Name, + Logger: e.Logger, + ExistingAddresses: ab, + DataStore: ds.Seal(), + NodeIDs: e.NodeIDs, + Offchain: e.Offchain, + GetContext: e.GetContext, + OCRSecrets: e.OCRSecrets, + OperationsBundle: e.OperationsBundle, + BlockChains: e.BlockChains, + DomainConfigGetter: e.DomainConfigGetter, } } diff --git a/deployment/environment_test.go b/deployment/environment_test.go new file mode 100644 index 000000000..bf777a258 --- /dev/null +++ b/deployment/environment_test.go @@ -0,0 +1,14 @@ +package deployment + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestNewEnvironment_DefaultDomainConfigGetter(t *testing.T) { + t.Parallel() + + env := NewNoopEnvironment(t) + require.NotNil(t, env.DomainConfigGetter) +}