1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlibabaCloud\Client\Clients; |
4
|
|
|
|
5
|
|
|
use AlibabaCloud\Client\AlibabaCloud; |
6
|
|
|
use AlibabaCloud\Client\Filter\Filter; |
7
|
|
|
use AlibabaCloud\Client\Request\Request; |
8
|
|
|
use AlibabaCloud\Client\Credentials\StsCredential; |
9
|
|
|
use AlibabaCloud\Client\Exception\ClientException; |
10
|
|
|
use AlibabaCloud\Client\Exception\ServerException; |
11
|
|
|
use AlibabaCloud\Client\Credentials\CredentialsInterface; |
12
|
|
|
use AlibabaCloud\Client\Credentials\EcsRamRoleCredential; |
13
|
|
|
use AlibabaCloud\Client\Credentials\RamRoleArnCredential; |
14
|
|
|
use AlibabaCloud\Client\Credentials\RsaKeyPairCredential; |
15
|
|
|
use AlibabaCloud\Client\Credentials\Providers\EcsRamRoleProvider; |
16
|
|
|
use AlibabaCloud\Client\Credentials\Providers\RamRoleArnProvider; |
17
|
|
|
use AlibabaCloud\Client\Credentials\Providers\RsaKeyPairProvider; |
18
|
|
|
use AlibabaCloud\Client\Credentials\Providers\CredentialsProvider; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Trait ManageTrait. |
22
|
|
|
* |
23
|
|
|
* @mixin Client |
24
|
|
|
*/ |
25
|
|
|
trait ManageTrait |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @param int $timeout |
29
|
|
|
* @param int $connectTimeout |
30
|
|
|
* |
31
|
|
|
* @return CredentialsInterface|StsCredential |
32
|
|
|
* |
33
|
|
|
* @throws ClientException |
34
|
|
|
* @throws ServerException |
35
|
|
|
*/ |
36
|
83 |
|
public function getSessionCredential($timeout = Request::TIMEOUT, $connectTimeout = Request::CONNECT_TIMEOUT) |
37
|
|
|
{ |
38
|
83 |
|
switch (\get_class($this->credential)) { |
39
|
83 |
|
case EcsRamRoleCredential::class: |
40
|
3 |
|
return (new EcsRamRoleProvider($this))->get(); |
41
|
80 |
|
case RamRoleArnCredential::class: |
42
|
5 |
|
return (new RamRoleArnProvider($this))->get($timeout, $connectTimeout); |
43
|
77 |
|
case RsaKeyPairCredential::class: |
44
|
4 |
|
return (new RsaKeyPairProvider($this))->get($timeout, $connectTimeout); |
45
|
73 |
|
default: |
46
|
75 |
|
return $this->credential; |
47
|
73 |
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return static |
52
|
|
|
* @throws ClientException |
53
|
|
|
* @deprecated |
54
|
|
|
* @codeCoverageIgnore |
55
|
|
|
*/ |
56
|
|
|
public function asGlobalClient() |
57
|
|
|
{ |
58
|
|
|
return $this->asDefaultClient(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Set the current client as the default client. |
63
|
|
|
* |
64
|
|
|
* @return static |
65
|
|
|
* @throws ClientException |
66
|
|
|
*/ |
67
|
62 |
|
public function asDefaultClient() |
68
|
|
|
{ |
69
|
62 |
|
return $this->name(CredentialsProvider::getDefaultName()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Naming clients. |
74
|
|
|
* |
75
|
|
|
* @param string $name |
76
|
|
|
* |
77
|
|
|
* @return static |
78
|
|
|
* @throws ClientException |
79
|
|
|
*/ |
80
|
129 |
|
public function name($name) |
81
|
|
|
{ |
82
|
129 |
|
Filter::name($name); |
83
|
|
|
|
84
|
127 |
|
return AlibabaCloud::set($name, $this); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return bool |
89
|
|
|
*/ |
90
|
23 |
|
public function isDebug() |
91
|
|
|
{ |
92
|
23 |
|
if (isset($this->options['debug'])) { |
93
|
2 |
|
return $this->options['debug'] === true && PHP_SAPI === 'cli'; |
94
|
|
|
} |
95
|
|
|
|
96
|
22 |
|
return false; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|