first commit -> move some files from one-api
This commit is contained in:
6
vendor/aws_sdk/Aws/Identity/S3/S3ExpressIdentity.php
vendored
Normal file
6
vendor/aws_sdk/Aws/Identity/S3/S3ExpressIdentity.php
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace Aws\Identity\S3;
|
||||
|
||||
use Aws\Credentials\Credentials;
|
||||
|
||||
class S3ExpressIdentity extends Credentials {}
|
||||
54
vendor/aws_sdk/Aws/Identity/S3/S3ExpressIdentityProvider.php
vendored
Normal file
54
vendor/aws_sdk/Aws/Identity/S3/S3ExpressIdentityProvider.php
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace Aws\Identity\S3;
|
||||
|
||||
use Aws;
|
||||
use Aws\LruArrayCache;
|
||||
use GuzzleHttp\Promise;
|
||||
|
||||
class S3ExpressIdentityProvider
|
||||
{
|
||||
|
||||
private $cache;
|
||||
private $region;
|
||||
private $config;
|
||||
private $s3Client;
|
||||
public function __construct($clientRegion, array $config = [])
|
||||
{
|
||||
$this->cache = new LruArrayCache(100);
|
||||
$this->region = $clientRegion;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function __invoke($command)
|
||||
{
|
||||
$s3Client = $this->getS3Client();
|
||||
$bucket = $command['Bucket'];
|
||||
if ($identity = $this->cache->get($bucket)) {
|
||||
if (!$identity->isExpired()) {
|
||||
return Promise\Create::promiseFor($identity);
|
||||
}
|
||||
}
|
||||
$response = $s3Client->createSession(['Bucket' => $bucket]);
|
||||
$identity = new Aws\Identity\S3\S3ExpressIdentity(
|
||||
$response['Credentials']['AccessKeyId'],
|
||||
$response['Credentials']['SecretAccessKey'],
|
||||
$response['Credentials']['SessionToken'],
|
||||
$response['Credentials']['Expiration']->getTimestamp()
|
||||
);
|
||||
$this->cache->set($bucket, $identity);
|
||||
return Promise\Create::promiseFor($identity);
|
||||
}
|
||||
|
||||
private function getS3Client()
|
||||
{
|
||||
if (is_null($this->s3Client)) {
|
||||
$this->s3Client = isset($this->config['client'])
|
||||
? $this->config['client'] // internal use only
|
||||
: new Aws\S3\S3Client([
|
||||
'region' => $this->region,
|
||||
'disable_express_session_auth' => true
|
||||
]);
|
||||
}
|
||||
return $this->s3Client;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user