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