| 1 | <?php |
||||||||||||||
| 2 | |||||||||||||||
| 3 | namespace AlibabaCloud\Client\Credentials\Providers; |
||||||||||||||
| 4 | |||||||||||||||
| 5 | use AlibabaCloud\Client\SDK; |
||||||||||||||
| 6 | use AlibabaCloud\Client\AlibabaCloud; |
||||||||||||||
| 7 | use AlibabaCloud\Client\Result\Result; |
||||||||||||||
| 8 | use AlibabaCloud\Client\Request\Request; |
||||||||||||||
| 9 | use AlibabaCloud\Client\Credentials\StsCredential; |
||||||||||||||
| 10 | use AlibabaCloud\Client\Exception\ClientException; |
||||||||||||||
| 11 | use AlibabaCloud\Client\Exception\ServerException; |
||||||||||||||
| 12 | use AlibabaCloud\Client\Credentials\Requests\AssumeRole; |
||||||||||||||
| 13 | |||||||||||||||
| 14 | /** |
||||||||||||||
| 15 | * Class RamRoleArnProvider |
||||||||||||||
| 16 | * |
||||||||||||||
| 17 | * @package AlibabaCloud\Client\Credentials\Providers |
||||||||||||||
| 18 | */ |
||||||||||||||
| 19 | class RamRoleArnProvider extends Provider |
||||||||||||||
| 20 | { |
||||||||||||||
| 21 | |||||||||||||||
| 22 | /** |
||||||||||||||
| 23 | * Get credential. |
||||||||||||||
| 24 | * |
||||||||||||||
| 25 | * |
||||||||||||||
| 26 | * @param int $timeout |
||||||||||||||
| 27 | * @param int $connectTimeout |
||||||||||||||
| 28 | * |
||||||||||||||
| 29 | * @return StsCredential |
||||||||||||||
| 30 | * @throws ClientException |
||||||||||||||
| 31 | * @throws ServerException |
||||||||||||||
| 32 | */ |
||||||||||||||
| 33 | 7 | public function get($timeout = Request::TIMEOUT, $connectTimeout = Request::CONNECT_TIMEOUT) |
|||||||||||||
| 34 | { |
||||||||||||||
| 35 | 7 | $credential = $this->getCredentialsInCache(); |
|||||||||||||
| 36 | |||||||||||||||
| 37 | 7 | if (null === $credential) { |
|||||||||||||
| 38 | 6 | $result = $this->request($timeout, $connectTimeout); |
|||||||||||||
| 39 | |||||||||||||||
| 40 | 2 | if (!isset($result['Credentials']['AccessKeyId'], |
|||||||||||||
| 41 | 2 | $result['Credentials']['AccessKeySecret'], |
|||||||||||||
| 42 | 2 | $result['Credentials']['SecurityToken'])) { |
|||||||||||||
| 43 | 1 | throw new ServerException($result, $this->error, SDK::INVALID_CREDENTIAL); |
|||||||||||||
| 44 | } |
||||||||||||||
| 45 | |||||||||||||||
| 46 | 1 | $credential = $result['Credentials']; |
|||||||||||||
| 47 | 1 | $this->cache($credential); |
|||||||||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||||||||||
| 48 | 1 | } |
|||||||||||||
| 49 | |||||||||||||||
| 50 | 2 | return new StsCredential( |
|||||||||||||
| 51 | 2 | $credential['AccessKeyId'], |
|||||||||||||
| 52 | 2 | $credential['AccessKeySecret'], |
|||||||||||||
| 53 | 2 | $credential['SecurityToken'] |
|||||||||||||
| 54 | 2 | ); |
|||||||||||||
| 55 | } |
||||||||||||||
| 56 | |||||||||||||||
| 57 | /** |
||||||||||||||
| 58 | * Get credentials by request. |
||||||||||||||
| 59 | * |
||||||||||||||
| 60 | * @param $timeout |
||||||||||||||
| 61 | * @param $connectTimeout |
||||||||||||||
| 62 | * |
||||||||||||||
| 63 | * @return Result |
||||||||||||||
| 64 | * @throws ClientException |
||||||||||||||
| 65 | * @throws ServerException |
||||||||||||||
| 66 | */ |
||||||||||||||
| 67 | 6 | private function request($timeout, $connectTimeout) |
|||||||||||||
| 68 | { |
||||||||||||||
| 69 | 6 | $clientName = __CLASS__ . \uniqid('ak', true); |
|||||||||||||
| 70 | 6 | $credential = $this->client->getCredential(); |
|||||||||||||
| 71 | |||||||||||||||
| 72 | 6 | AlibabaCloud::accessKeyClient( |
|||||||||||||
| 73 | 6 | $credential->getAccessKeyId(), |
|||||||||||||
|
0 ignored issues
–
show
The method
getAccessKeyId() does not exist on AlibabaCloud\Client\Cred...ls\CredentialsInterface. It seems like you code against a sub-type of said class. However, the method does not exist in AlibabaCloud\Client\Cred...ls\RsaKeyPairCredential or AlibabaCloud\Client\Cred...ls\EcsRamRoleCredential. Are you sure you never get one of those?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
The method
getAccessKeyId() does not exist on AlibabaCloud\Client\Cred...ls\EcsRamRoleCredential.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
The method
getAccessKeyId() does not exist on AlibabaCloud\Client\Cred...ls\RsaKeyPairCredential.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||||||||||
| 74 | 6 | $credential->getAccessKeySecret() |
|||||||||||||
|
0 ignored issues
–
show
The method
getAccessKeySecret() does not exist on AlibabaCloud\Client\Cred...ls\CredentialsInterface. It seems like you code against a sub-type of said class. However, the method does not exist in AlibabaCloud\Client\Cred...ls\RsaKeyPairCredential or AlibabaCloud\Client\Cred...ls\EcsRamRoleCredential. Are you sure you never get one of those?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
The method
getAccessKeySecret() does not exist on AlibabaCloud\Client\Cred...ls\EcsRamRoleCredential.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
The method
getAccessKeySecret() does not exist on AlibabaCloud\Client\Cred...ls\RsaKeyPairCredential.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||||||||||
| 75 | 6 | )->name($clientName); |
|||||||||||||
| 76 | |||||||||||||||
| 77 | 6 | return (new AssumeRole($credential)) |
|||||||||||||
|
0 ignored issues
–
show
It seems like
$credential can also be of type AlibabaCloud\Client\Cred...als\AccessKeyCredential and AlibabaCloud\Client\Cred...s\BearerTokenCredential and AlibabaCloud\Client\Cred...ls\EcsRamRoleCredential and AlibabaCloud\Client\Cred...ls\RsaKeyPairCredential and AlibabaCloud\Client\Credentials\StsCredential; however, parameter $arnCredential of AlibabaCloud\Client\Cred...sumeRole::__construct() does only seem to accept AlibabaCloud\Client\Cred...ls\RamRoleArnCredential, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||||||||
| 78 | 6 | ->client($clientName) |
|||||||||||||
| 79 | 6 | ->timeout($timeout) |
|||||||||||||
| 80 | 6 | ->connectTimeout($connectTimeout) |
|||||||||||||
| 81 | 6 | ->debug($this->client->isDebug()) |
|||||||||||||
| 82 | 6 | ->request(); |
|||||||||||||
| 83 | } |
||||||||||||||
| 84 | } |
||||||||||||||
| 85 |