Skip to content

Commit

Permalink
docs: update IMDSv2 doc for ecs ram role
Browse files Browse the repository at this point in the history
  • Loading branch information
yndu13 committed May 24, 2024
1 parent 22dc2e4 commit 727cc41
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
11 changes: 7 additions & 4 deletions README-zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,15 @@ $ramRoleArn->getPolicy();

use AlibabaCloud\Credentials\Credential;

$ecsRamRole = new Credential([
'type' => 'ecs_ram_role',
'role_name' => '<role_name>',
$config = new Credential\Config([
'type' => 'ecs_ram_role',
'roleName' => '<role_name>',
'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
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '<role_name>',
$config = new Credential\Config([
'type' => 'ecs_ram_role',
'roleName' => '<role_name>',
'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
Expand Down
6 changes: 4 additions & 2 deletions tests/Feature/CredentialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 727cc41

Please sign in to comment.