1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlibabaCloud\Client\Credentials; |
4
|
|
|
|
5
|
|
|
use AlibabaCloud\Client\Exception\ClientException; |
6
|
|
|
use AlibabaCloud\Client\Filter\CredentialFilter; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Use the AssumeRole of the RAM account to complete the authentication. |
10
|
|
|
* |
11
|
|
|
* @package AlibabaCloud\Client\Credentials |
12
|
|
|
*/ |
13
|
|
|
class RamRoleArnCredential implements CredentialsInterface |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private $accessKeyId; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $accessKeySecret; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $roleArn; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $roleSessionName; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
private $policy; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Class constructor. |
43
|
|
|
* |
44
|
|
|
* @param string $accessKeyId |
45
|
|
|
* @param string $accessKeySecret |
46
|
|
|
* @param string $roleArn |
47
|
|
|
* @param string $roleSessionName |
48
|
|
|
* @param string $policy |
49
|
|
|
* |
50
|
|
|
* @throws ClientException |
51
|
|
|
*/ |
52
|
20 |
|
public function __construct($accessKeyId, $accessKeySecret, $roleArn, $roleSessionName, $policy = '') |
53
|
|
|
{ |
54
|
20 |
|
CredentialFilter::AccessKey($accessKeyId, $accessKeySecret); |
55
|
|
|
|
56
|
12 |
|
$this->accessKeyId = $accessKeyId; |
57
|
12 |
|
$this->accessKeySecret = $accessKeySecret; |
58
|
12 |
|
$this->roleArn = $roleArn; |
59
|
12 |
|
$this->roleSessionName = $roleSessionName; |
60
|
12 |
|
$this->policy = $policy; |
61
|
12 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
9 |
|
public function getAccessKeyId() |
67
|
|
|
{ |
68
|
9 |
|
return $this->accessKeyId; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
9 |
|
public function getAccessKeySecret() |
75
|
|
|
{ |
76
|
9 |
|
return $this->accessKeySecret; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
10 |
|
public function getRoleArn() |
83
|
|
|
{ |
84
|
10 |
|
return $this->roleArn; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
10 |
|
public function getRoleSessionName() |
91
|
|
|
{ |
92
|
10 |
|
return $this->roleSessionName; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
7 |
|
public function getPolicy() |
99
|
|
|
{ |
100
|
7 |
|
return $this->policy; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
10 |
|
public function __toString() |
107
|
|
|
{ |
108
|
10 |
|
return "$this->accessKeyId#$this->accessKeySecret#$this->roleArn#$this->roleSessionName"; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|