Skip to content
Merged
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
13 changes: 13 additions & 0 deletions pkg/loop/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"go.uber.org/zap/zapcore"

"github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/settings/cresettings"
)

const (
Expand Down Expand Up @@ -76,6 +77,9 @@ const (

envChipIngressEndpoint = "CL_CHIP_INGRESS_ENDPOINT"
envChipIngressInsecureConnection = "CL_CHIP_INGRESS_INSECURE_CONNECTION"

envCRESettings = cresettings.EnvNameSettings
envCRESettingsDefault = cresettings.EnvNameSettingsDefault
)

// EnvConfig is the configuration between the application and the LOOP executable. The values
Expand Down Expand Up @@ -142,6 +146,9 @@ type EnvConfig struct {

ChipIngressEndpoint string
ChipIngressInsecureConnection bool

CRESettings string
CRESettingsDefault string
}

// AsCmdEnv returns a slice of environment variable key/value pairs for an exec.Cmd.
Expand Down Expand Up @@ -222,6 +229,9 @@ func (e *EnvConfig) AsCmdEnv() (env []string) {
add(envChipIngressEndpoint, e.ChipIngressEndpoint)
add(envChipIngressInsecureConnection, strconv.FormatBool(e.ChipIngressInsecureConnection))

add(envCRESettings, e.CRESettings)
add(envCRESettingsDefault, e.CRESettingsDefault)

return
}

Expand Down Expand Up @@ -426,6 +436,9 @@ func (e *EnvConfig) parse() error {
}
}

e.CRESettings = os.Getenv(envCRESettings)
e.CRESettingsDefault = os.Getenv(envCRESettingsDefault)

return nil
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/loop/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func TestEnvConfig_parse(t *testing.T) {

envChipIngressEndpoint: "chip-ingress.example.com:50051",
envChipIngressInsecureConnection: "true",

envCRESettings: `{"global":{}}`,
envCRESettingsDefault: `{"foo":"bar"}`,
},
expectError: false,
expectConfig: envCfgFull,
Expand Down Expand Up @@ -177,6 +180,9 @@ var envCfgFull = EnvConfig{

ChipIngressEndpoint: "chip-ingress.example.com:50051",
ChipIngressInsecureConnection: true,

CRESettings: `{"global":{}}`,
CRESettingsDefault: `{"foo":"bar"}`,
}

func TestEnvConfig_AsCmdEnv(t *testing.T) {
Expand Down Expand Up @@ -228,6 +234,9 @@ func TestEnvConfig_AsCmdEnv(t *testing.T) {
// Assert ChipIngress environment variables
assert.Equal(t, "chip-ingress.example.com:50051", got[envChipIngressEndpoint])
assert.Equal(t, "true", got[envChipIngressInsecureConnection])

assert.Equal(t, `{"global":{}}`, got[envCRESettings])
assert.Equal(t, `{"foo":"bar"}`, got[envCRESettingsDefault])
}

func TestGetMap(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/settings/cresettings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import (
)

const (
envNameSettings = "CL_CRE_SETTINGS"
envNameSettingsDefault = "CL_CRE_SETTINGS_DEFAULT"
EnvNameSettings = "CL_CRE_SETTINGS"
EnvNameSettingsDefault = "CL_CRE_SETTINGS_DEFAULT"
)

func init() { reinit() }
func reinit() {
if v, ok := os.LookupEnv(envNameSettingsDefault); ok {
if v, ok := os.LookupEnv(EnvNameSettingsDefault); ok {
err := json.Unmarshal([]byte(v), &Default)
if err != nil {
log.Fatalf("failed to initialize defaults: %v", err)
Expand All @@ -35,7 +35,7 @@ func reinit() {
}
Config = Default

if v, ok := os.LookupEnv(envNameSettings); ok {
if v, ok := os.LookupEnv(EnvNameSettings); ok {
DefaultGetter, err = NewJSONGetter([]byte(v))
if err != nil {
log.Fatalf("failed to initialize settings: %v", err)
Expand Down
12 changes: 6 additions & 6 deletions pkg/settings/cresettings/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestDefaultGetter(t *testing.T) {
require.Equal(t, 5, got)

t.Cleanup(reinit) // restore default vars
t.Setenv(envNameSettings, `{
t.Setenv(EnvNameSettings, `{
"workflow": {
"test-wf-id": {
"PerWorkflow": {
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestDefaultGetter_SettingMap(t *testing.T) {
t.Cleanup(reinit) // restore default vars

// Org override to allow
t.Setenv(envNameSettings, `{
t.Setenv(EnvNameSettings, `{
"workflow": {
"test-wf-id": {
"PerWorkflow": {
Expand All @@ -213,7 +213,7 @@ func TestDefaultGetter_SettingMap(t *testing.T) {
require.True(t, got)

// Org override to allow by default, but disallow some
t.Setenv(envNameSettings, `{
t.Setenv(EnvNameSettings, `{
"workflow": {
"test-wf-id": {
"PerWorkflow": {
Expand Down Expand Up @@ -247,7 +247,7 @@ func TestDefaultEnvVars(t *testing.T) {
t.Cleanup(reinit) // restore after

// update defaults
t.Setenv(envNameSettingsDefault, `{
t.Setenv(EnvNameSettingsDefault, `{
"PerWorkflow": {
"ChainAllowed": {
"Values": {
Expand All @@ -274,8 +274,8 @@ func TestDefaultEnvVars(t *testing.T) {
assert.NoError(t, gl.AllowErr(contexts.WithChainSelector(ctx, 1234)))

// update overrides
t.Setenv(envNameSettingsDefault, "{}")
t.Setenv(envNameSettings, `{
t.Setenv(EnvNameSettingsDefault, "{}")
t.Setenv(EnvNameSettings, `{
"global": {
"PerWorkflow": {
"ChainAllowed": {
Expand Down
Loading