|
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\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
|
|
|
* @throws ServerException |
|
34
|
|
|
*/ |
|
35
|
74 |
|
public function getSessionCredential($timeout = \ALIBABA_CLOUD_TIMEOUT) |
|
36
|
|
|
{ |
|
37
|
74 |
|
switch (\get_class($this->credential)) { |
|
38
|
74 |
|
case EcsRamRoleCredential::class: |
|
39
|
9 |
|
return (new EcsRamRoleProvider($this))->get(); |
|
40
|
65 |
|
case RamRoleArnCredential::class: |
|
41
|
7 |
|
return (new RamRoleArnProvider($this))->get($timeout); |
|
42
|
58 |
|
case RsaKeyPairCredential::class: |
|
43
|
8 |
|
return (new RsaKeyPairProvider($this))->get($timeout); |
|
44
|
50 |
|
default: |
|
45
|
50 |
|
return $this->credential; |
|
46
|
50 |
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Naming clients. |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $name |
|
53
|
|
|
* |
|
54
|
|
|
* @return static |
|
55
|
|
|
* @throws ClientException |
|
56
|
|
|
*/ |
|
57
|
136 |
|
public function name($name) |
|
58
|
|
|
{ |
|
59
|
136 |
|
Filter::name($name); |
|
60
|
|
|
|
|
61
|
134 |
|
return AlibabaCloud::set($name, $this); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @deprecated |
|
66
|
|
|
* @codeCoverageIgnore |
|
67
|
|
|
* Set the current client as the global client. |
|
68
|
|
|
* |
|
69
|
|
|
* @return static |
|
70
|
|
|
* @throws ClientException |
|
71
|
|
|
*/ |
|
72
|
|
|
public function asGlobalClient() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->asDefaultClient(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Set the current client as the default client. |
|
79
|
|
|
* |
|
80
|
|
|
* @return static |
|
81
|
|
|
* @throws ClientException |
|
82
|
|
|
*/ |
|
83
|
38 |
|
public function asDefaultClient() |
|
84
|
|
|
{ |
|
85
|
38 |
|
return $this->name(CredentialsProvider::getDefaultName()); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return bool |
|
90
|
|
|
*/ |
|
91
|
39 |
|
public function isDebug() |
|
92
|
|
|
{ |
|
93
|
39 |
|
if (isset($this->options['debug'])) { |
|
94
|
2 |
|
return true === $this->options['debug'] && PHP_SAPI === 'cli'; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
38 |
|
return false; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|