diff --git a/README-CN.md b/README-CN.md index 3c87e34..6b1f740 100644 --- a/README-CN.md +++ b/README-CN.md @@ -229,8 +229,8 @@ 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"). - // `EnableIMDSv2` is optional and is recommended to be turned on. It can be replaced by setting environment variable: ALIBABA_CLOUD_ECS_IMDSV2_ENABLE - SetEnableIMDSv2(true) + // `DisableIMDSv1` is optional and is recommended to be turned on. It can be replaced by setting environment variable: ALIBABA_CLOUD_IMDSV1_DISABLE + SetDisableIMDSv1(true) provider, err := credentials.NewCredential(config) if err != nil { diff --git a/README.md b/README.md index 35b2f79..d65f5c8 100644 --- a/README.md +++ b/README.md @@ -248,8 +248,8 @@ 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"). - // `EnableIMDSv2` is optional and is recommended to be turned on. It can be replaced by setting environment variable: ALIBABA_CLOUD_ECS_IMDSV2_ENABLE - SetEnableIMDSv2(true) + // `DisableIMDSv1` is optional and is recommended to be turned on. It can be replaced by setting environment variable: ALIBABA_CLOUD_IMDSV1_DISABLE + SetDisableIMDSv1(true) provider, err := credentials.NewCredential(config) if err != nil { diff --git a/credentials/credential.go b/credentials/credential.go index 2739c6a..f7f635a 100644 --- a/credentials/credential.go +++ b/credentials/credential.go @@ -115,6 +115,11 @@ func (s *Config) SetEnableIMDSv2(v bool) *Config { return s } +func (s *Config) SetDisableIMDSv1(v bool) *Config { + s.DisableIMDSv1 = &v + return s +} + func (s *Config) SetMetadataTokenDuration(v int) *Config { s.MetadataTokenDuration = &v return s diff --git a/credentials/credential_test.go b/credentials/credential_test.go index d602183..f4544c6 100644 --- a/credentials/credential_test.go +++ b/credentials/credential_test.go @@ -125,11 +125,21 @@ func TestNewCredentialWithECSRAMRole(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, cred) + config.SetDisableIMDSv1(false) + cred, err = NewCredential(config) + assert.Nil(t, err) + assert.NotNil(t, cred) + config.SetEnableIMDSv2(true) cred, err = NewCredential(config) assert.Nil(t, err) assert.NotNil(t, cred) + config.SetDisableIMDSv1(true) + cred, err = NewCredential(config) + assert.Nil(t, err) + assert.NotNil(t, cred) + config.SetEnableIMDSv2(true) config.SetMetadataTokenDuration(180) cred, err = NewCredential(config)