Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix empty security token issue #115

Merged
merged 2 commits into from
Aug 29, 2024
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
2 changes: 1 addition & 1 deletion credentials/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func NewCredential(config *Config) (credential Credential, err error) {
credential = fromCredentialsProvider("ecs_ram_role", provider)
case "ram_role_arn":
var credentialsProvider providers.CredentialsProvider
if config.SecurityToken != nil {
if config.SecurityToken != nil && *config.SecurityToken != "" {
credentialsProvider, err = providers.NewStaticSTSCredentialsProviderBuilder().
WithAccessKeyId(tea.StringValue(config.AccessKeyId)).
WithAccessKeySecret(tea.StringValue(config.AccessKeySecret)).
Expand Down
12 changes: 12 additions & 0 deletions credentials/credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ func TestNewCredentialWithRAMRoleARN(t *testing.T) {
cred, err = NewCredential(config)
assert.Nil(t, err)
assert.NotNil(t, cred)

// empty security token should ok
config.SetSecurityToken("")
cred, err = NewCredential(config)
assert.Nil(t, err)
assert.NotNil(t, cred)

// with sts should ok
config.SetSecurityToken("securitytoken")
cred, err = NewCredential(config)
assert.Nil(t, err)
assert.NotNil(t, cred)
}

func TestNewCredentialWithBearerToken(t *testing.T) {
Expand Down