|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AlibabaCloud\Client\Filter; |
|
4
|
|
|
|
|
5
|
|
|
use AlibabaCloud\Client\SDK; |
|
6
|
|
|
use AlibabaCloud\Client\Exception\ClientException; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class CredentialFilter |
|
10
|
|
|
* |
|
11
|
|
|
* @package AlibabaCloud\Client\Filter |
|
12
|
|
|
*/ |
|
13
|
|
|
class CredentialFilter |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @param $bearerToken |
|
17
|
|
|
* |
|
18
|
|
|
* @return mixed |
|
19
|
|
|
* @throws ClientException |
|
20
|
|
|
*/ |
|
21
|
23 |
|
public static function bearerToken($bearerToken) |
|
22
|
|
|
{ |
|
23
|
23 |
|
if (!is_string($bearerToken)) { |
|
24
|
2 |
|
throw new ClientException( |
|
25
|
2 |
|
'Bearer Token must be a string', |
|
26
|
|
|
SDK::INVALID_ARGUMENT |
|
27
|
2 |
|
); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
21 |
|
if ($bearerToken === '') { |
|
31
|
2 |
|
throw new ClientException( |
|
32
|
2 |
|
'Bearer Token cannot be empty', |
|
33
|
|
|
SDK::INVALID_ARGUMENT |
|
34
|
2 |
|
); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
19 |
|
return $bearerToken; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param $publicKeyId |
|
42
|
|
|
* |
|
43
|
|
|
* @return mixed |
|
44
|
|
|
* @throws ClientException |
|
45
|
|
|
*/ |
|
46
|
24 |
|
public static function publicKeyId($publicKeyId) |
|
47
|
|
|
{ |
|
48
|
24 |
|
if (!is_string($publicKeyId)) { |
|
49
|
2 |
|
throw new ClientException( |
|
50
|
2 |
|
'Public Key ID must be a string', |
|
51
|
|
|
SDK::INVALID_ARGUMENT |
|
52
|
2 |
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
22 |
|
if ($publicKeyId === '') { |
|
56
|
2 |
|
throw new ClientException( |
|
57
|
2 |
|
'Public Key ID cannot be empty', |
|
58
|
|
|
SDK::INVALID_ARGUMENT |
|
59
|
2 |
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
20 |
|
return $publicKeyId; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param $privateKeyFile |
|
67
|
|
|
* |
|
68
|
|
|
* @return mixed |
|
69
|
|
|
* @throws ClientException |
|
70
|
|
|
*/ |
|
71
|
20 |
|
public static function privateKeyFile($privateKeyFile) |
|
72
|
|
|
{ |
|
73
|
20 |
|
if (!is_string($privateKeyFile)) { |
|
74
|
2 |
|
throw new ClientException( |
|
75
|
2 |
|
'Private Key File must be a string', |
|
76
|
|
|
SDK::INVALID_ARGUMENT |
|
77
|
2 |
|
); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
18 |
|
if ($privateKeyFile === '') { |
|
81
|
2 |
|
throw new ClientException( |
|
82
|
2 |
|
'Private Key File cannot be empty', |
|
83
|
|
|
SDK::INVALID_ARGUMENT |
|
84
|
2 |
|
); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
16 |
|
return $privateKeyFile; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param $roleName |
|
92
|
|
|
* |
|
93
|
|
|
* @return string |
|
94
|
|
|
* |
|
95
|
|
|
* @throws ClientException |
|
96
|
|
|
*/ |
|
97
|
24 |
|
public static function roleName($roleName) |
|
98
|
|
|
{ |
|
99
|
24 |
|
if (!is_string($roleName)) { |
|
100
|
2 |
|
throw new ClientException( |
|
101
|
2 |
|
'Role Name must be a string', |
|
102
|
|
|
SDK::INVALID_ARGUMENT |
|
103
|
2 |
|
); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
22 |
|
if ($roleName === '') { |
|
107
|
2 |
|
throw new ClientException( |
|
108
|
2 |
|
'Role Name cannot be empty', |
|
109
|
|
|
SDK::INVALID_ARGUMENT |
|
110
|
2 |
|
); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
20 |
|
return $roleName; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @param string $accessKeyId |
|
118
|
|
|
* @param string $accessKeySecret |
|
119
|
|
|
* |
|
120
|
|
|
* @throws ClientException |
|
121
|
|
|
*/ |
|
122
|
141 |
|
public static function AccessKey($accessKeyId, $accessKeySecret) |
|
123
|
|
|
{ |
|
124
|
141 |
|
if (!is_string($accessKeyId)) { |
|
|
|
|
|
|
125
|
6 |
|
throw new ClientException( |
|
126
|
6 |
|
'AccessKey ID must be a string', |
|
127
|
|
|
SDK::INVALID_ARGUMENT |
|
128
|
6 |
|
); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
135 |
|
if ($accessKeyId === '') { |
|
132
|
6 |
|
throw new ClientException( |
|
133
|
6 |
|
'AccessKey ID cannot be empty', |
|
134
|
|
|
SDK::INVALID_ARGUMENT |
|
135
|
6 |
|
); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
129 |
|
if (str_replace(' ', '', $accessKeyId) !== $accessKeyId) { |
|
139
|
6 |
|
throw new ClientException( |
|
140
|
6 |
|
'AccessKey ID format is invalid', |
|
141
|
|
|
SDK::INVALID_ARGUMENT |
|
142
|
6 |
|
); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
123 |
|
if (!is_string($accessKeySecret)) { |
|
|
|
|
|
|
146
|
6 |
|
throw new ClientException( |
|
147
|
6 |
|
'AccessKey Secret must be a string', |
|
148
|
|
|
SDK::INVALID_ARGUMENT |
|
149
|
6 |
|
); |
|
150
|
|
|
} |
|
151
|
117 |
|
|
|
152
|
|
|
if ($accessKeySecret === '') { |
|
153
|
|
|
throw new ClientException( |
|
154
|
|
|
'AccessKey Secret cannot be empty', |
|
155
|
|
|
SDK::INVALID_ARGUMENT |
|
156
|
|
|
); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
if (str_replace(' ', '', $accessKeySecret) !== $accessKeySecret) { |
|
160
|
|
|
throw new ClientException( |
|
161
|
|
|
'AccessKey Secret format is invalid', |
|
162
|
|
|
SDK::INVALID_ARGUMENT |
|
163
|
|
|
); |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|