diff --git a/README-zh-CN.md b/README-zh-CN.md index ad127c4..bd2a695 100644 --- a/README-zh-CN.md +++ b/README-zh-CN.md @@ -113,12 +113,15 @@ $ramRoleArn->getPolicy(); use AlibabaCloud\Credentials\Credential; -$ecsRamRole = new Credential([ - 'type' => 'ecs_ram_role', - 'role_name' => '', +$config = new Credential\Config([ + 'type' => 'ecs_ram_role', + 'roleName' => '', + 'enableIMDSv2' => true, ]); +$ecsRamRole = new Credential($config); $ecsRamRole->getRoleName(); -// Note: `role_name` is optional. It will be retrieved automatically if not set. It is highly recommended to set it up to reduce requests. +// Note: `roleName` is optional. It will be retrieved automatically if not set. It is highly recommended to set it up to reduce requests. +// Note: `enableIMDSv2` is optional and is recommended to be turned on. It can be replaced by setting environment variable: ALIBABA_CLOUD_ECS_IMDSV2_ENABLE ``` #### RsaKeyPair diff --git a/README.md b/README.md index 86939cd..bcb4bb0 100644 --- a/README.md +++ b/README.md @@ -113,12 +113,15 @@ By specifying the role name, the credential will be able to automatically reques use AlibabaCloud\Credentials\Credential; -$ecsRamRole = new Credential([ - 'type' => 'ecs_ram_role', - 'role_name' => '', +$config = new Credential\Config([ + 'type' => 'ecs_ram_role', + 'roleName' => '', + 'enableIMDSv2' => true, ]); +$ecsRamRole = new Credential($config); $ecsRamRole->getRoleName(); -// Note: `role_name` is optional. It will be retrieved automatically if not set. It is highly recommended to set it up to reduce requests. +// Note: `roleName` is optional. It will be retrieved automatically if not set. It is highly recommended to set it up to reduce requests. +// Note: `enableIMDSv2` is optional and is recommended to be turned on. It can be replaced by setting environment variable: ALIBABA_CLOUD_ECS_IMDSV2_ENABLE ``` #### RsaKeyPair diff --git a/tests/Feature/CredentialTest.php b/tests/Feature/CredentialTest.php index a797fe8..f8b1970 100644 --- a/tests/Feature/CredentialTest.php +++ b/tests/Feature/CredentialTest.php @@ -46,14 +46,16 @@ public function testAccessKey() public function testEcsRamRoleCredential() { $config = new Credential\Config([ - 'type' => 'ecs_ram_role', - 'roleName' => 'foo', + 'type' => 'ecs_ram_role', + 'roleName' => 'foo', + 'enableIMDSv2' => true, ]); $credential = new Credential($config); // Assert $this->assertEquals('foo', $credential->getRoleName()); $this->assertEquals('ecs_ram_role', $credential->getType()); + $this->assertTrue($credential['enableIMDSv2']); $credential->getAccessKeySecret(); }