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
media-cloud-sync / includes / sdk / s3 / Aws / Identity / S3 / S3ExpressIdentityProvider.php

S3ExpressIdentityProvider.php in Media Cloud Sync 1.4.2, at includes/sdk/s3/Aws/Identity/S3/S3ExpressIdentityProvider.php

42 lines 1.5 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\Identity\S3;
4
5 use Dudlewebs\WPMCS\s3\Aws;
6 use Dudlewebs\WPMCS\s3\Aws\LruArrayCache;
7 use Dudlewebs\WPMCS\s3\GuzzleHttp\Promise;
8 class S3ExpressIdentityProvider
9 {
10 private $cache;
11 private $region;
12 private $config;
13 private $s3Client;
14 public function __construct($clientRegion, array $config = [])
15 {
16 $this->cache = new LruArrayCache(100);
17 $this->region = $clientRegion;
18 $this->config = $config;
19 }
20 public function __invoke($command)
21 {
22 $s3Client = $this->getS3Client();
23 $bucket = $command['Bucket'];
24 if ($identity = $this->cache->get($bucket)) {
25 if (!$identity->isExpired()) {
26 return Promise\Create::promiseFor($identity);
27 }
28 }
29 $response = $s3Client->createSession(['Bucket' => $bucket]);
30 $identity = new Aws\Identity\S3\S3ExpressIdentity($response['Credentials']['AccessKeyId'], $response['Credentials']['SecretAccessKey'], $response['Credentials']['SessionToken'], $response['Credentials']['Expiration']->getTimestamp());
31 $this->cache->set($bucket, $identity);
32 return Promise\Create::promiseFor($identity);
33 }
34 private function getS3Client()
35 {
36 if (\is_null($this->s3Client)) {
37 $this->s3Client = $this->config['client'] ?? new Aws\S3\S3Client(['region' => $this->region, 'disable_express_session_auth' => \true]);
38 }
39 return $this->s3Client;
40 }
41 }
42