Skip to content

Commit

Permalink
Fix loading env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcl committed Jul 12, 2024
1 parent 701c39a commit 2a47487
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 43 deletions.
2 changes: 1 addition & 1 deletion integration-tests/ccip-tests/testconfig/ccip.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func (c *CCIP) LoadFromEnv() error {
if c.Env == nil {
c.Env = &Common{}
}
err := c.Env.LoadFromEnv()
err := c.Env.ReadFromEnvVar()
if err != nil {
return err
}
Expand Down
181 changes: 142 additions & 39 deletions integration-tests/ccip-tests/testconfig/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/smartcontractkit/seth"

"github.com/smartcontractkit/chainlink-testing-framework/docker/test_env"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/networks"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
Expand Down Expand Up @@ -137,7 +138,7 @@ func NewConfig() (*Config, error) {
}
// read secrets for all products
if cfg.CCIP != nil {
err := ctfconfig.LoadSecretDotEnvFiles()
err := ctfconfig.LoadSecretEnvsFromFiles()
if err != nil {
return nil, errors.Wrap(err, "error loading testsecrets files")
}
Expand Down Expand Up @@ -169,28 +170,151 @@ type Common struct {
Logging *ctfconfig.LoggingConfig `toml:",omitempty"`
}

// LoadFromEnv loads selected env vars into the config
func (p *Common) LoadFromEnv() error {
if p.Logging == nil {
p.Logging = &ctfconfig.LoggingConfig{}
// ReadFromEnvVar loads selected env vars into the config
func (p *Common) ReadFromEnvVar() error {
logger := logging.GetTestLogger(nil)

lokiTenantID := ctfconfig.MustReadEnvVar_String(ctfconfig.E2E_TEST_LOKI_TENANT_ID_ENV)
if lokiTenantID != "" {
if p.Logging == nil {
p.Logging = &ctfconfig.LoggingConfig{}
}
if p.Logging.Loki == nil {
p.Logging.Loki = &ctfconfig.LokiConfig{}
}
logger.Debug().Msgf("Using %s env var to override Logging.Loki.TenantId", ctfconfig.E2E_TEST_LOKI_TENANT_ID_ENV)
p.Logging.Loki.TenantId = &lokiTenantID
}
err := p.Logging.LoadFromEnv()
if err != nil {
return errors.Wrap(err, "error loading logging config from env")

lokiEndpoint := ctfconfig.MustReadEnvVar_String(ctfconfig.E2E_TEST_LOKI_ENDPOINT_ENV)
if lokiEndpoint != "" {
if p.Logging == nil {
p.Logging = &ctfconfig.LoggingConfig{}
}
if p.Logging.Loki == nil {
p.Logging.Loki = &ctfconfig.LokiConfig{}
}
logger.Debug().Msgf("Using %s env var to override Logging.Loki.Endpoint", ctfconfig.E2E_TEST_LOKI_ENDPOINT_ENV)
p.Logging.Loki.Endpoint = &lokiEndpoint
}
if p.Network == nil {
p.Network = &ctfconfig.NetworkConfig{}

lokiBasicAuth := ctfconfig.MustReadEnvVar_String(ctfconfig.E2E_TEST_LOKI_BASIC_AUTH_ENV)
if lokiBasicAuth != "" {
if p.Logging == nil {
p.Logging = &ctfconfig.LoggingConfig{}
}
if p.Logging.Loki == nil {
p.Logging.Loki = &ctfconfig.LokiConfig{}
}
logger.Debug().Msgf("Using %s env var to override Logging.Loki.BasicAuth", ctfconfig.E2E_TEST_LOKI_BASIC_AUTH_ENV)
p.Logging.Loki.BasicAuth = &lokiBasicAuth
}
err = p.Network.LoadFromEnv()
if err != nil {
return errors.Wrap(err, "error loading network config from env")

lokiBearerToken := ctfconfig.MustReadEnvVar_String(ctfconfig.E2E_TEST_LOKI_BEARER_TOKEN_ENV)
if lokiBearerToken != "" {
if p.Logging == nil {
p.Logging = &ctfconfig.LoggingConfig{}
}
if p.Logging.Loki == nil {
p.Logging.Loki = &ctfconfig.LokiConfig{}
}
logger.Debug().Msgf("Using %s env var to override Logging.Loki.BearerToken", ctfconfig.E2E_TEST_LOKI_BEARER_TOKEN_ENV)
p.Logging.Loki.BearerToken = &lokiBearerToken
}
if p.NewCLCluster == nil {
p.NewCLCluster = &ChainlinkDeployment{}

grafanaBaseUrl := ctfconfig.MustReadEnvVar_String(ctfconfig.E2E_TEST_GRAFANA_BASE_URL_ENV)
if grafanaBaseUrl != "" {
if p.Logging == nil {
p.Logging = &ctfconfig.LoggingConfig{}
}
if p.Logging.Grafana == nil {
p.Logging.Grafana = &ctfconfig.GrafanaConfig{}
}
logger.Debug().Msgf("Using %s env var to override Logging.Grafana.BaseUrl", ctfconfig.E2E_TEST_GRAFANA_BASE_URL_ENV)
p.Logging.Grafana.BaseUrl = &grafanaBaseUrl
}
err = p.NewCLCluster.LoadFromEnv()
if err != nil {
return errors.Wrap(err, "error loading chainlink deployment config from env")

grafanaDashboardUrl := ctfconfig.MustReadEnvVar_String(ctfconfig.E2E_TEST_GRAFANA_DASHBOARD_URL_ENV)
if grafanaDashboardUrl != "" {
if p.Logging == nil {
p.Logging = &ctfconfig.LoggingConfig{}
}
if p.Logging.Grafana == nil {
p.Logging.Grafana = &ctfconfig.GrafanaConfig{}
}
logger.Debug().Msgf("Using %s env var to override Logging.Grafana.DashboardUrl", ctfconfig.E2E_TEST_GRAFANA_DASHBOARD_URL_ENV)
p.Logging.Grafana.DashboardUrl = &grafanaDashboardUrl
}

grafanaBearerToken := ctfconfig.MustReadEnvVar_String(ctfconfig.E2E_TEST_GRAFANA_BEARER_TOKEN_ENV)
if grafanaBearerToken != "" {
if p.Logging == nil {
p.Logging = &ctfconfig.LoggingConfig{}
}
if p.Logging.Grafana == nil {
p.Logging.Grafana = &ctfconfig.GrafanaConfig{}
}
logger.Debug().Msgf("Using %s env var to override Logging.Grafana.BearerToken", ctfconfig.E2E_TEST_GRAFANA_BEARER_TOKEN_ENV)
p.Logging.Grafana.BearerToken = &grafanaBearerToken
}

walletKeys := ctfconfig.ReadEnvVarGroupedMap(ctfconfig.E2E_TEST_WALLET_KEY_ENV, ctfconfig.E2E_TEST_WALLET_KEYS_ENV)
if len(walletKeys) > 0 {
if p.Network == nil {
p.Network = &ctfconfig.NetworkConfig{}
}
logger.Debug().Msgf("Using %s and/or %s env vars to override Network.WalletKeys", ctfconfig.E2E_TEST_WALLET_KEY_ENV, ctfconfig.E2E_TEST_WALLET_KEYS_ENV)
p.Network.WalletKeys = walletKeys
}

rpcHttpUrls := ctfconfig.ReadEnvVarGroupedMap(ctfconfig.E2E_TEST_RPC_HTTP_URL_ENV, ctfconfig.E2E_TEST_RPC_HTTP_URLS_ENV)
if len(rpcHttpUrls) > 0 {
if p.Network == nil {
p.Network = &ctfconfig.NetworkConfig{}
}
logger.Debug().Msgf("Using %s and/or %s env vars to override Network.RpcHttpUrls", ctfconfig.E2E_TEST_RPC_HTTP_URL_ENV, ctfconfig.E2E_TEST_RPC_HTTP_URLS_ENV)
p.Network.RpcHttpUrls = rpcHttpUrls
}

rpcWsUrls := ctfconfig.ReadEnvVarGroupedMap(ctfconfig.E2E_TEST_RPC_WS_URL_ENV, ctfconfig.E2E_TEST_RPC_WS_URLS_ENV)
if len(rpcWsUrls) > 0 {
if p.Network == nil {
p.Network = &ctfconfig.NetworkConfig{}
}
logger.Debug().Msgf("Using %s and/or %s env vars to override Network.RpcWsUrls", ctfconfig.E2E_TEST_RPC_WS_URL_ENV, ctfconfig.E2E_TEST_RPC_WS_URLS_ENV)
p.Network.RpcWsUrls = rpcWsUrls
}

chainlinkImage := ctfconfig.MustReadEnvVar_String(ctfconfig.E2E_TEST_CHAINLINK_IMAGE_ENV)
if chainlinkImage != "" {
if p.NewCLCluster == nil {
p.NewCLCluster = &ChainlinkDeployment{}
}
if p.NewCLCluster.Common == nil {
p.NewCLCluster.Common = &Node{}
}
if p.NewCLCluster.Common.ChainlinkImage == nil {
p.NewCLCluster.Common.ChainlinkImage = &ctfconfig.ChainlinkImageConfig{}
}

logger.Debug().Msgf("Using %s env var to override NewCLCluster.Common.ChainlinkImage.Image", ctfconfig.E2E_TEST_CHAINLINK_IMAGE_ENV)
p.NewCLCluster.Common.ChainlinkImage.Image = &chainlinkImage
}

chainlinkUpgradeImage := ctfconfig.MustReadEnvVar_String(ctfconfig.E2E_TEST_CHAINLINK_UPGRADE_IMAGE_ENV)
if chainlinkUpgradeImage != "" {
if p.NewCLCluster == nil {
p.NewCLCluster = &ChainlinkDeployment{}
}
if p.NewCLCluster.Common == nil {
p.NewCLCluster.Common = &Node{}
}
if p.NewCLCluster.Common.ChainlinkUpgradeImage == nil {
p.NewCLCluster.Common.ChainlinkUpgradeImage = &ctfconfig.ChainlinkImageConfig{}
}

logger.Debug().Msgf("Using %s env var to override NewCLCluster.Common.ChainlinkUpgradeImage.Image", ctfconfig.E2E_TEST_CHAINLINK_UPGRADE_IMAGE_ENV)
p.NewCLCluster.Common.ChainlinkUpgradeImage.Image = &chainlinkUpgradeImage
}

return nil
Expand Down Expand Up @@ -360,27 +484,6 @@ type ChainlinkDeployment struct {
Nodes []*Node `toml:",omitempty"` // to be mentioned only if diff nodes follow diff configs; not required if all nodes follow CommonConfig
}

func (c *ChainlinkDeployment) LoadFromEnv() error {
if c.Common == nil {
c.Common = &Node{}
}
if c.Common.ChainlinkImage == nil {
c.Common.ChainlinkImage = &ctfconfig.ChainlinkImageConfig{}
}
err := c.Common.ChainlinkImage.LoadFromEnv("E2E_TEST_CHAINLINK_IMAGE")
if err != nil {
return err
}
if c.Common.ChainlinkUpgradeImage == nil {
c.Common.ChainlinkUpgradeImage = &ctfconfig.ChainlinkImageConfig{}
}
err = c.Common.ChainlinkUpgradeImage.LoadFromEnv("E2E_TEST_CHAINLINK_UPGRADE_IMAGE")
if err != nil {
return err
}
return nil
}

func (c *ChainlinkDeployment) Validate() error {
if c.Common == nil {
return errors.New("common config can't be empty")
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ require (
exclude github.com/hashicorp/consul v1.2.1

replace (
github.com/smartcontractkit/chainlink-testing-framework => github.com/smartcontractkit/chainlink-testing-framework v1.32.3-0.20240712120531-caf8ae6267ad
github.com/smartcontractkit/chainlink-testing-framework => github.com/smartcontractkit/chainlink-testing-framework v1.32.3-0.20240712142233-00b78cd832b4

k8s.io/api => k8s.io/api v0.25.11
k8s.io/client-go => k8s.io/client-go v0.25.11
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20230303024457-afdc3dddf62d
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1435,8 +1435,8 @@ github.com/smartcontractkit/chainlink-solana v1.0.3-0.20240701154249-032706dcb7c
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20240701154249-032706dcb7c8/go.mod h1:NbXXQaNFskVMYRut0MvBlcHu/vDgipGMwYjamvjVB9Y=
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20240625074951-06ab5e670dba h1:YNSlhK5mobyAaw02LPGgIEuS3lXyCTXcc6oaV2L6uUI=
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20240625074951-06ab5e670dba/go.mod h1:UVFRacRkP7O7TQAzFmR52v5mUlxf+G1ovMlCQAB/cHU=
github.com/smartcontractkit/chainlink-testing-framework v1.32.3-0.20240712120531-caf8ae6267ad h1:emG8Ea6NKnfDUpbv52fuK4kDRrvixcCZ3mI/uRG3ptQ=
github.com/smartcontractkit/chainlink-testing-framework v1.32.3-0.20240712120531-caf8ae6267ad/go.mod h1:OYlILtWsQskqZgzIjRe7PpIEySJVhb4qMnGxOuzrUgA=
github.com/smartcontractkit/chainlink-testing-framework v1.32.3-0.20240712142233-00b78cd832b4 h1:fTqVXHYSS3OK5nJEzBNKHMcyM9qebtm8ggfct8moeY0=
github.com/smartcontractkit/chainlink-testing-framework v1.32.3-0.20240712142233-00b78cd832b4/go.mod h1:OYlILtWsQskqZgzIjRe7PpIEySJVhb4qMnGxOuzrUgA=
github.com/smartcontractkit/chainlink-testing-framework/grafana v0.0.0-20240405215812-5a72bc9af239 h1:Kk5OVlx/5g9q3Z3lhxytZS4/f8ds1MiNM8yaHgK3Oe8=
github.com/smartcontractkit/chainlink-testing-framework/grafana v0.0.0-20240405215812-5a72bc9af239/go.mod h1:DC8sQMyTlI/44UCTL8QWFwb0bYNoXCfjwCv2hMivYZU=
github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868 h1:FFdvEzlYwcuVHkdZ8YnZR/XomeMGbz5E2F2HZI3I3w8=
Expand Down

0 comments on commit 2a47487

Please sign in to comment.