Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions deployment/domain_config_getter.go
Original file line number Diff line number Diff line change
@@ -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)
}
31 changes: 31 additions & 0 deletions deployment/domain_config_getter_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
28 changes: 16 additions & 12 deletions deployment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned that this is now bleeding CLD internals (domains) into an environment which doesn't need to know about this.

Think about a case like devenv where they may not actually have domains.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may be more of a naming problem though.

If we remove Domain then I understand where this would work

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i think domain may be the wrong name for it as the name couples the domain concept into cld

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when its purpose is just to be a generic getter for configs

}
}

Expand Down
14 changes: 14 additions & 0 deletions deployment/environment_test.go
Original file line number Diff line number Diff line change
@@ -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)
}