From e3948a903a0244d84d6f9cb33fcee38cd9ad481d Mon Sep 17 00:00:00 2001 From: yndu13 Date: Sat, 14 Sep 2024 09:42:51 +0800 Subject: [PATCH] refactor config setters --- credentials/credential.go | 5 +++++ credentials/credential_test.go | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/credentials/credential.go b/credentials/credential.go index f7f635a..d049761 100644 --- a/credentials/credential.go +++ b/credentials/credential.go @@ -198,6 +198,11 @@ func (s *Config) SetSTSEndpoint(v string) *Config { return s } +func (s *Config) SetExternalId(v string) *Config { + s.ExternalId = &v + return s +} + // NewCredential return a credential according to the type in config. // if config is nil, the function will use default provider chain to get credentials. // please see README.md for detail. diff --git a/credentials/credential_test.go b/credentials/credential_test.go index f4544c6..227235c 100644 --- a/credentials/credential_test.go +++ b/credentials/credential_test.go @@ -232,6 +232,15 @@ func TestNewCredentialWithRAMRoleARN(t *testing.T) { cred, err = NewCredential(config) assert.Nil(t, err) assert.NotNil(t, cred) + + config.SetExternalId("externalId") + config.SetPolicy("policy") + config.SetRoleSessionExpiration(3600) + config.SetRoleSessionName("roleSessionName") + cred, err = NewCredential(config) + assert.Nil(t, err) + assert.NotNil(t, cred) + } func TestNewCredentialWithBearerToken(t *testing.T) {