PluginProbe
Media Cloud Sync / 1.2.6
Media Cloud Sync v1.2.6
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 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / Credentials / AssumeRoleCredentialProvider.php

AssumeRoleCredentialProvider.php in Media Cloud Sync 1.2.6, at includes/sdk/s3/Aws/Credentials/AssumeRoleCredentialProvider.php

54 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\Credentials;
4
5 use Dudlewebs\WPMCS\s3\Aws\Exception\CredentialsException;
6 use Dudlewebs\WPMCS\s3\Aws\Result;
7 use Dudlewebs\WPMCS\s3\Aws\Sts\StsClient;
8 use Dudlewebs\WPMCS\s3\GuzzleHttp\Promise\PromiseInterface;
9 /**
10 * Credential provider that provides credentials via assuming a role
11 * More Information, see: http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-sts-2011-06-15.html#assumerole
12 */
13 class AssumeRoleCredentialProvider
14 {
15 const ERROR_MSG = "Missing required 'AssumeRoleCredentialProvider' configuration option: ";
16 /** @var StsClient */
17 private $client;
18 /** @var array */
19 private $assumeRoleParams;
20 /**
21 * The constructor requires following configure parameters:
22 * - client: a StsClient
23 * - assume_role_params: Parameters used to make assumeRole call
24 *
25 * @param array $config Configuration options
26 * @throws \InvalidArgumentException
27 */
28 public function __construct(array $config = [])
29 {
30 if (!isset($config['assume_role_params'])) {
31 throw new \InvalidArgumentException(self::ERROR_MSG . "'assume_role_params'.");
32 }
33 if (!isset($config['client'])) {
34 throw new \InvalidArgumentException(self::ERROR_MSG . "'client'.");
35 }
36 $this->client = $config['client'];
37 $this->assumeRoleParams = $config['assume_role_params'];
38 }
39 /**
40 * Loads assume role credentials.
41 *
42 * @return PromiseInterface
43 */
44 public function __invoke()
45 {
46 $client = $this->client;
47 return $client->assumeRoleAsync($this->assumeRoleParams)->then(function (Result $result) {
48 return $this->client->createCredentials($result);
49 })->otherwise(function (\RuntimeException $exception) {
50 throw new CredentialsException("Error in retrieving assume role credentials.", 0, $exception);
51 });
52 }
53 }
54