From 268a44a8096f5784e6a9f56ea1b69334ffd10c69 Mon Sep 17 00:00:00 2001 From: mozillazg Date: Fri, 3 Feb 2023 14:21:04 +0800 Subject: [PATCH] oidc credentials provider allow use default value ("defaultSessionName") as RoleSessionName --- credentials/oidc_credential_provider.go | 1 + credentials/oidc_credential_provider_test.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/credentials/oidc_credential_provider.go b/credentials/oidc_credential_provider.go index 98ded60..928eb93 100644 --- a/credentials/oidc_credential_provider.go +++ b/credentials/oidc_credential_provider.go @@ -27,6 +27,7 @@ func (p *oidcCredentialsProvider) resolve() (*Config, error) { RoleArn: tea.String(roleArn), OIDCProviderArn: tea.String(oidcProviderArn), OIDCTokenFilePath: tea.String(oidcTokenFilePath), + RoleSessionName: tea.String("defaultSessionName"), } roleSessionName, ok := os.LookupEnv(ENVRoleSessionName) if ok { diff --git a/credentials/oidc_credential_provider_test.go b/credentials/oidc_credential_provider_test.go index fbf1029..67b9acb 100644 --- a/credentials/oidc_credential_provider_test.go +++ b/credentials/oidc_credential_provider_test.go @@ -31,6 +31,15 @@ func TestOidcCredentialsProvider(t *testing.T) { os.Setenv(ENVRoleArn, "roleArn") os.Setenv(ENVOIDCProviderArn, "oidcProviderArn") os.Setenv(ENVOIDCTokenFile, "oidcTokenFilePath") + os.Unsetenv(ENVRoleSessionName) + c, err = p.resolve() + assert.Nil(t, err) + assert.Equal(t, "roleArn", tea.StringValue(c.RoleArn)) + assert.Equal(t, "oidcProviderArn", tea.StringValue(c.OIDCProviderArn)) + assert.Equal(t, "oidcTokenFilePath", tea.StringValue(c.OIDCTokenFilePath)) + assert.Equal(t, "defaultSessionName", tea.StringValue(c.RoleSessionName)) + assert.Equal(t, "oidc_role_arn", tea.StringValue(c.Type)) + os.Setenv(ENVRoleSessionName, "roleSessionName") c, err = p.resolve() assert.Nil(t, err)