← All changes
|
includes/sdk/s3/Aws/Credentials/EcsCredentialProvider.php
+10
-1
1.2.13
→
1.4.2
View file →
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Dudlewebs\WPMCS\s3\Aws\Credentials; |
| 4 | 4 | |
| 5 | +use Dudlewebs\WPMCS\s3\Aws\Arn\Arn; | |
| 5 | 6 | use Dudlewebs\WPMCS\s3\Aws\Exception\CredentialsException; |
| 6 | 7 | use Dudlewebs\WPMCS\s3\GuzzleHttp\Exception\ConnectException; |
| 7 | 8 | use Dudlewebs\WPMCS\s3\GuzzleHttp\Exception\GuzzleException; |
| 8 | 9 | use Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7\Request; |
| @@ -66,9 +67,17 @@ | ||
| 66 | 67 | $credentials = null; |
| 67 | 68 | while ($credentials === null) { |
| 68 | 69 | $credentials = (yield $client($request, ['timeout' => $this->timeout, 'proxy' => '', 'headers' => $headers])->then(function (ResponseInterface $response) { |
| 69 | 70 | $result = $this->decodeResult((string) $response->getBody()); |
| 70 | - return new Credentials($result['AccessKeyId'], $result['SecretAccessKey'], $result['Token'], \strtotime($result['Expiration']), $result['AccountId'] ?? null); | |
| 71 | + if (!isset($result['AccountId']) && isset($result['RoleArn'])) { | |
| 72 | + try { | |
| 73 | + $parsedArn = new Arn($result['RoleArn']); | |
| 74 | + $result['AccountId'] = $parsedArn->getAccountId(); | |
| 75 | + } catch (\Exception $e) { | |
| 76 | + // AccountId will be null | |
| 77 | + } | |
| 78 | + } | |
| 79 | + return new Credentials($result['AccessKeyId'], $result['SecretAccessKey'], $result['Token'], \strtotime($result['Expiration']), $result['AccountId'] ?? null, CredentialSources::ECS); | |
| 71 | 80 | })->otherwise(function ($reason) { |
| 72 | 81 | $reason = \is_array($reason) ? $reason['exception'] : $reason; |
| 73 | 82 | $isRetryable = $reason instanceof ConnectException; |
| 74 | 83 | if ($isRetryable && $this->attempts < $this->retries) { |