123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- namespace Aws\Sts;
- use Aws\AwsClient;
- use Aws\CacheInterface;
- use Aws\Credentials\Credentials;
- use Aws\Result;
- use Aws\Sts\RegionalEndpoints\ConfigurationProvider;
- class StsClient extends AwsClient
- {
-
- public function __construct(array $args)
- {
- if (
- !isset($args['sts_regional_endpoints'])
- || $args['sts_regional_endpoints'] instanceof CacheInterface
- ) {
- $args['sts_regional_endpoints'] = ConfigurationProvider::defaultProvider($args);
- }
- $this->addBuiltIns($args);
- parent::__construct($args);
- }
-
- public function createCredentials(Result $result)
- {
- if (!$result->hasKey('Credentials')) {
- throw new \InvalidArgumentException('Result contains no credentials');
- }
- $c = $result['Credentials'];
- return new Credentials(
- $c['AccessKeyId'],
- $c['SecretAccessKey'],
- isset($c['SessionToken']) ? $c['SessionToken'] : null,
- isset($c['Expiration']) && $c['Expiration'] instanceof \DateTimeInterface
- ? (int) $c['Expiration']->format('U')
- : null
- );
- }
-
- private function addBuiltIns($args)
- {
- $key = 'AWS::STS::UseGlobalEndpoint';
- $result = $args['sts_regional_endpoints'] instanceof \Closure ?
- $args['sts_regional_endpoints']()->wait() : $args['sts_regional_endpoints'];
- if (is_string($result)) {
- if ($result === 'regional') {
- $value = false;
- } else if ($result === 'legacy') {
- $value = true;
- } else {
- return;
- }
- } else {
- if ($result->getEndpointsType() === 'regional') {
- $value = false;
- } else {
- $value = true;
- }
- }
- $this->clientBuiltIns[$key] = $value;
- }
- }
|