1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlibabaCloud\Client\Credentials; |
4
|
|
|
|
5
|
|
|
use AlibabaCloud\Client\Filter\CredentialFilter; |
6
|
|
|
use AlibabaCloud\Client\Exception\ClientException; |
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|array $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
|
8 |
|
public function getPolicy() |
99
|
|
|
{ |
100
|
8 |
|
return $this->policy; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
11 |
|
public function __toString() |
107
|
|
|
{ |
108
|
11 |
|
return "$this->accessKeyId#$this->accessKeySecret#$this->roleArn#$this->roleSessionName"; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.