Skip to content

Commit

Permalink
AliCloud access keys #335
Browse files Browse the repository at this point in the history
AliCloud access keys
  • Loading branch information
oliverbundalo authored Aug 15, 2024
2 parents dc9be5d + f65f34a commit f4f4be8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 32 deletions.
2 changes: 2 additions & 0 deletions e2e/framework/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"os"
"path"
"strconv"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -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)
})
Expand Down
13 changes: 2 additions & 11 deletions e2e/framework/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
64 changes: 43 additions & 21 deletions secrets/alibaba/alibaba_ssm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"strings"

"github.com/0xPolygon/polygon-edge/secrets"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -236,6 +224,40 @@ 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,
}
} else {
config = &openapi.Config{
// 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 variable ALICLOUD_SECRET_KEY is set.
AccessKeySecret: tea.String(os.Getenv("ALICLOUD_SECRET_KEY")),
}
}

// oos.eu-central-1.aliyuncs.com
config.Endpoint = tea.String(a.endpoint)
// eu-central-1
config.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
Expand Down

0 comments on commit f4f4be8

Please sign in to comment.