Skip to content

Commit

Permalink
fix: update to env ALIBABA_CLOUD_IMDSV1_DISABLED for imds v1 disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
yndu13 committed Sep 12, 2024
1 parent e541552 commit 1d5d242
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func main(){
SetType("ecs_ram_role").
// `roleName` is optional. It will be retrieved automatically if not set. It is highly recommended to set it up to reduce requests
SetRoleName("RoleName").
// `DisableIMDSv1` is optional and is recommended to be turned on. It can be replaced by setting environment variable: ALIBABA_CLOUD_IMDSV1_DISABLE
// `DisableIMDSv1` is optional and is recommended to be turned on. It can be replaced by setting environment variable: ALIBABA_CLOUD_IMDSV1_DISABLED
SetDisableIMDSv1(true)

provider, err := credentials.NewCredential(config)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func main(){
SetType("ecs_ram_role").
// `roleName` is optional. It will be retrieved automatically if not set. It is highly recommended to set it up to reduce requests
SetRoleName("RoleName").
// `DisableIMDSv1` is optional and is recommended to be turned on. It can be replaced by setting environment variable: ALIBABA_CLOUD_IMDSV1_DISABLE
// `DisableIMDSv1` is optional and is recommended to be turned on. It can be replaced by setting environment variable: ALIBABA_CLOUD_IMDSV1_DISABLED
SetDisableIMDSv1(true)

provider, err := credentials.NewCredential(config)
Expand Down
2 changes: 1 addition & 1 deletion credentials/internal/providers/ecs_ram_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (builder *ECSRAMRoleCredentialsProviderBuilder) Build() (provider *ECSRAMRo
}

if !builder.provider.disableIMDSv1 {
builder.provider.disableIMDSv1 = os.Getenv("ALIBABA_CLOUD_IMDSV1_DISABLE") == "true"
builder.provider.disableIMDSv1 = os.Getenv("ALIBABA_CLOUD_IMDSV1_DISABLED") == "true"
}

provider = builder.provider
Expand Down
4 changes: 2 additions & 2 deletions credentials/internal/providers/ecs_ram_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,14 @@ func TestECSRAMRoleCredentialsProvider_getMetadataToken(t *testing.T) {
_, err = p.getMetadataToken()
assert.Nil(t, err)

os.Setenv("ALIBABA_CLOUD_IMDSV1_DISABLE", "true")
os.Setenv("ALIBABA_CLOUD_IMDSV1_DISABLED", "true")
p, err = NewECSRAMRoleCredentialsProviderBuilder().Build()
assert.Nil(t, err)

_, err = p.getMetadataToken()
assert.NotNil(t, err)

os.Setenv("ALIBABA_CLOUD_IMDSV1_DISABLE", "")
os.Setenv("ALIBABA_CLOUD_IMDSV1_DISABLED", "")
p, err = NewECSRAMRoleCredentialsProviderBuilder().Build()
assert.Nil(t, err)

Expand Down

0 comments on commit 1d5d242

Please sign in to comment.