PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
← 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) {