From 311a6911d609991ddf7aad53be62e91dfd6e76ad Mon Sep 17 00:00:00 2001 From: Oliver Bundalo Date: Wed, 14 Aug 2024 11:26:01 +0200 Subject: [PATCH 1/4] AliCloud access keys --- secrets/alibaba/alibaba_ssm.go | 67 +++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/secrets/alibaba/alibaba_ssm.go b/secrets/alibaba/alibaba_ssm.go index da53bde725..2a5ff41e42 100644 --- a/secrets/alibaba/alibaba_ssm.go +++ b/secrets/alibaba/alibaba_ssm.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "os" "strings" "github.com/0xPolygon/polygon-edge/secrets" @@ -45,25 +46,25 @@ func SecretsManagerFactory( } // Check if the extra map is present - if config.Extra == nil || - config.Extra["region"] == nil || - config.Extra["ssm-parameter-path"] == nil || - config.Extra["role"] == nil { - return nil, errors.New("required extra map containing 'region' and 'ssm-parameter-path' " + - "and 'role' not found for alibaba-ssm") + if config.Extra == nil || config.Extra["region"] == nil || config.Extra["ssm-parameter-path"] == nil { + return nil, errors.New("required extra map containing 'region' and 'ssm-parameter-path' not found for alibaba-ssm") } // / Set up the base object alibabaSsmManager := &AlibabaSsmManager{ logger: params.Logger.Named(string(secrets.AlibabaSSM)), region: fmt.Sprintf("%v", config.Extra["region"]), - role: fmt.Sprintf("%v", config.Extra["role"]), endpoint: config.ServerURL, } // Set the base path to store the secrets in OOS parameter store alibabaSsmManager.basePath = fmt.Sprintf("%s/%s", config.Extra["ssm-parameter-path"], config.Name) + // Set role if found + if config.Extra["role"] != nil { + alibabaSsmManager.role = fmt.Sprintf("%v", config.Extra["role"]) + } + // Run the initial setup if err := alibabaSsmManager.Setup(); err != nil { return nil, err @@ -74,24 +75,11 @@ func SecretsManagerFactory( // Setup sets up the Alibaba secrets manager func (a *AlibabaSsmManager) Setup() error { - creds, err := getCredentials(a.role) + config, err := a.getSdkConfig() if err != nil { return err } - config := &openapi.Config{ - // Required - AccessKeyId: creds.AccessKeyId, - // Required - AccessKeySecret: creds.AccessKeySecret, - // Required - SecurityToken: creds.SecurityToken, - // config.Endpoint = tea.String("oos.eu-central-1.aliyuncs.com") - Endpoint: tea.String(a.endpoint), - // eu-central-1 - RegionId: tea.String(a.region), - } - client, err := oos20190601.NewClient(config) if err != nil { return err @@ -236,6 +224,43 @@ func (a *AlibabaSsmManager) logError(err error) { } } +func (a *AlibabaSsmManager) getSdkConfig() (*openapi.Config, error) { + var config *openapi.Config + + if a.role != "" { + creds, err := getCredentials(a.role) + if err != nil { + return nil, err + } + + config = &openapi.Config{ + // Required + AccessKeyId: creds.AccessKeyId, + // Required + AccessKeySecret: creds.AccessKeySecret, + // Required + SecurityToken: creds.SecurityToken, + // config.Endpoint = tea.String("oos.eu-central-1.aliyuncs.com") + Endpoint: tea.String(a.endpoint), + // eu-central-1 + RegionId: tea.String(a.region), + } + } else { + config = &openapi.Config{ + // Required, please ensure that the environment variables ALICLOUD_ACCESS_KEY is set. + AccessKeyId: tea.String(os.Getenv("ALICLOUD_ACCESS_KEY")), + // Required, please ensure that the environment variables ALICLOUD_SECRET_KEY is set. + AccessKeySecret: tea.String(os.Getenv("ALICLOUD_SECRET_KEY")), + // config.Endpoint = tea.String("oos.eu-central-1.aliyuncs.com") + Endpoint: tea.String(a.endpoint), + // eu-central-1 + RegionId: tea.String(a.region), + } + } + + return config, nil +} + func getCredentials(role string) (*aliyun.CredentialModel, error) { config := new(aliyun.Config). // Which type of credential you want From 87a61a2f3723cf93ce9bf75468563027c59c85e4 Mon Sep 17 00:00:00 2001 From: Oliver Bundalo Date: Wed, 14 Aug 2024 11:46:02 +0200 Subject: [PATCH 2/4] Code clean up --- secrets/alibaba/alibaba_ssm.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/secrets/alibaba/alibaba_ssm.go b/secrets/alibaba/alibaba_ssm.go index 2a5ff41e42..c96b58ccaf 100644 --- a/secrets/alibaba/alibaba_ssm.go +++ b/secrets/alibaba/alibaba_ssm.go @@ -240,24 +240,21 @@ func (a *AlibabaSsmManager) getSdkConfig() (*openapi.Config, error) { AccessKeySecret: creds.AccessKeySecret, // Required SecurityToken: creds.SecurityToken, - // config.Endpoint = tea.String("oos.eu-central-1.aliyuncs.com") - Endpoint: tea.String(a.endpoint), - // eu-central-1 - RegionId: tea.String(a.region), } } else { config = &openapi.Config{ - // Required, please ensure that the environment variables ALICLOUD_ACCESS_KEY is set. + // Required, please ensure that the environment variable ALICLOUD_ACCESS_KEY is set. AccessKeyId: tea.String(os.Getenv("ALICLOUD_ACCESS_KEY")), - // Required, please ensure that the environment variables ALICLOUD_SECRET_KEY is set. + // Required, please ensure that the environment variable ALICLOUD_SECRET_KEY is set. AccessKeySecret: tea.String(os.Getenv("ALICLOUD_SECRET_KEY")), - // config.Endpoint = tea.String("oos.eu-central-1.aliyuncs.com") - Endpoint: tea.String(a.endpoint), - // eu-central-1 - RegionId: tea.String(a.region), } } + // oos.eu-central-1.aliyuncs.com + config.Endpoint = tea.String(a.endpoint) + // eu-central-1 + config.RegionId = tea.String(a.region) + return config, nil } From ef0ce937d19dda46c8a3912f5c1d870bbca7455c Mon Sep 17 00:00:00 2001 From: Oliver Bundalo Date: Wed, 14 Aug 2024 16:03:50 +0200 Subject: [PATCH 3/4] Set server name for logging file name --- e2e/framework/helper.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/e2e/framework/helper.go b/e2e/framework/helper.go index ac8dde882c..4b697ba5c3 100644 --- a/e2e/framework/helper.go +++ b/e2e/framework/helper.go @@ -8,6 +8,7 @@ import ( "net" "os" "path" + "strconv" "strings" "sync" "testing" @@ -345,6 +346,7 @@ func NewTestServers(t *testing.T, num int, conf func(*TestServerConfig)) []*Test srv := NewTestServer(t, dataDir, func(c *TestServerConfig) { c.SetLogsDir(logsDir) + c.SetName(strconv.Itoa(i)) c.SetSaveLogs(true) conf(c) }) From f65f34ab9230739a1ac3e9f1b04a75625c7e6a9f Mon Sep 17 00:00:00 2001 From: Oliver Bundalo Date: Wed, 14 Aug 2024 16:43:38 +0200 Subject: [PATCH 4/4] chainID removed since it's not used --- e2e/framework/testserver.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/e2e/framework/testserver.go b/e2e/framework/testserver.go index 4efc72d9db..a1788e44dd 100644 --- a/e2e/framework/testserver.go +++ b/e2e/framework/testserver.go @@ -49,9 +49,8 @@ const ( type TestServer struct { t *testing.T - Config *TestServerConfig - cmd *exec.Cmd - chainID *big.Int + Config *TestServerConfig + cmd *exec.Cmd } func NewTestServer(t *testing.T, rootDir string, callback TestServerConfigCallback) *TestServer { @@ -274,14 +273,6 @@ func (t *TestServer) Start(ctx context.Context) error { return err } - // query the chain id - chainID, err := t.JSONRPC().ChainID() - if err != nil { - return err - } - - t.chainID = chainID - return nil }