Laravel version update
Laravel version update
This commit is contained in:
@@ -5,6 +5,7 @@ use Aws\CacheInterface;
|
||||
use Aws\CommandInterface;
|
||||
use Aws\LruArrayCache;
|
||||
use Aws\MultiRegionClient as BaseClient;
|
||||
use Aws\Exception\AwsException;
|
||||
use Aws\S3\Exception\PermanentRedirectException;
|
||||
use GuzzleHttp\Promise;
|
||||
|
||||
@@ -23,10 +24,18 @@ use GuzzleHttp\Promise;
|
||||
* @method \GuzzleHttp\Promise\Promise createMultipartUploadAsync(array $args = [])
|
||||
* @method \Aws\Result deleteBucket(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteBucketAsync(array $args = [])
|
||||
* @method \Aws\Result deleteBucketAnalyticsConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteBucketAnalyticsConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result deleteBucketCors(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteBucketCorsAsync(array $args = [])
|
||||
* @method \Aws\Result deleteBucketEncryption(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteBucketEncryptionAsync(array $args = [])
|
||||
* @method \Aws\Result deleteBucketInventoryConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteBucketInventoryConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result deleteBucketLifecycle(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteBucketLifecycleAsync(array $args = [])
|
||||
* @method \Aws\Result deleteBucketMetricsConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteBucketMetricsConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result deleteBucketPolicy(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteBucketPolicyAsync(array $args = [])
|
||||
* @method \Aws\Result deleteBucketReplication(array $args = [])
|
||||
@@ -37,14 +46,22 @@ use GuzzleHttp\Promise;
|
||||
* @method \GuzzleHttp\Promise\Promise deleteBucketWebsiteAsync(array $args = [])
|
||||
* @method \Aws\Result deleteObject(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteObjectAsync(array $args = [])
|
||||
* @method \Aws\Result deleteObjectTagging(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteObjectTaggingAsync(array $args = [])
|
||||
* @method \Aws\Result deleteObjects(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteObjectsAsync(array $args = [])
|
||||
* @method \Aws\Result getBucketAccelerateConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBucketAccelerateConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result getBucketAcl(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBucketAclAsync(array $args = [])
|
||||
* @method \Aws\Result getBucketAnalyticsConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBucketAnalyticsConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result getBucketCors(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBucketCorsAsync(array $args = [])
|
||||
* @method \Aws\Result getBucketEncryption(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBucketEncryptionAsync(array $args = [])
|
||||
* @method \Aws\Result getBucketInventoryConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBucketInventoryConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result getBucketLifecycle(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBucketLifecycleAsync(array $args = [])
|
||||
* @method \Aws\Result getBucketLifecycleConfiguration(array $args = [])
|
||||
@@ -53,6 +70,8 @@ use GuzzleHttp\Promise;
|
||||
* @method \GuzzleHttp\Promise\Promise getBucketLocationAsync(array $args = [])
|
||||
* @method \Aws\Result getBucketLogging(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBucketLoggingAsync(array $args = [])
|
||||
* @method \Aws\Result getBucketMetricsConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBucketMetricsConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result getBucketNotification(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBucketNotificationAsync(array $args = [])
|
||||
* @method \Aws\Result getBucketNotificationConfiguration(array $args = [])
|
||||
@@ -73,12 +92,20 @@ use GuzzleHttp\Promise;
|
||||
* @method \GuzzleHttp\Promise\Promise getObjectAsync(array $args = [])
|
||||
* @method \Aws\Result getObjectAcl(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getObjectAclAsync(array $args = [])
|
||||
* @method \Aws\Result getObjectTagging(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getObjectTaggingAsync(array $args = [])
|
||||
* @method \Aws\Result getObjectTorrent(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getObjectTorrentAsync(array $args = [])
|
||||
* @method \Aws\Result headBucket(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise headBucketAsync(array $args = [])
|
||||
* @method \Aws\Result headObject(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise headObjectAsync(array $args = [])
|
||||
* @method \Aws\Result listBucketAnalyticsConfigurations(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listBucketAnalyticsConfigurationsAsync(array $args = [])
|
||||
* @method \Aws\Result listBucketInventoryConfigurations(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listBucketInventoryConfigurationsAsync(array $args = [])
|
||||
* @method \Aws\Result listBucketMetricsConfigurations(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listBucketMetricsConfigurationsAsync(array $args = [])
|
||||
* @method \Aws\Result listBuckets(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listBucketsAsync(array $args = [])
|
||||
* @method \Aws\Result listMultipartUploads(array $args = [])
|
||||
@@ -95,14 +122,22 @@ use GuzzleHttp\Promise;
|
||||
* @method \GuzzleHttp\Promise\Promise putBucketAccelerateConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result putBucketAcl(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putBucketAclAsync(array $args = [])
|
||||
* @method \Aws\Result putBucketAnalyticsConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putBucketAnalyticsConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result putBucketCors(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putBucketCorsAsync(array $args = [])
|
||||
* @method \Aws\Result putBucketEncryption(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putBucketEncryptionAsync(array $args = [])
|
||||
* @method \Aws\Result putBucketInventoryConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putBucketInventoryConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result putBucketLifecycle(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putBucketLifecycleAsync(array $args = [])
|
||||
* @method \Aws\Result putBucketLifecycleConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putBucketLifecycleConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result putBucketLogging(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putBucketLoggingAsync(array $args = [])
|
||||
* @method \Aws\Result putBucketMetricsConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putBucketMetricsConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result putBucketNotification(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putBucketNotificationAsync(array $args = [])
|
||||
* @method \Aws\Result putBucketNotificationConfiguration(array $args = [])
|
||||
@@ -123,6 +158,8 @@ use GuzzleHttp\Promise;
|
||||
* @method \GuzzleHttp\Promise\Promise putObjectAsync(array $args = [])
|
||||
* @method \Aws\Result putObjectAcl(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putObjectAclAsync(array $args = [])
|
||||
* @method \Aws\Result putObjectTagging(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putObjectTaggingAsync(array $args = [])
|
||||
* @method \Aws\Result restoreObject(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise restoreObjectAsync(array $args = [])
|
||||
* @method \Aws\Result uploadPart(array $args = [])
|
||||
@@ -132,9 +169,7 @@ use GuzzleHttp\Promise;
|
||||
*/
|
||||
class S3MultiRegionClient extends BaseClient implements S3ClientInterface
|
||||
{
|
||||
use S3ClientTrait {
|
||||
determineBucketRegionAsync as private lookupBucketRegion;
|
||||
}
|
||||
use S3ClientTrait;
|
||||
|
||||
/** @var CacheInterface */
|
||||
private $cache;
|
||||
@@ -142,7 +177,11 @@ class S3MultiRegionClient extends BaseClient implements S3ClientInterface
|
||||
public static function getArguments()
|
||||
{
|
||||
$args = parent::getArguments();
|
||||
$args['region']['default'] = 'us-east-1';
|
||||
$regionDef = $args['region'] + ['default' => function (array &$args) {
|
||||
$availableRegions = array_keys($args['partition']['regions']);
|
||||
return end($availableRegions);
|
||||
}];
|
||||
unset($args['region']);
|
||||
|
||||
return $args + [
|
||||
'bucket_region_cache' => [
|
||||
@@ -151,6 +190,7 @@ class S3MultiRegionClient extends BaseClient implements S3ClientInterface
|
||||
'doc' => 'Cache of regions in which given buckets are located.',
|
||||
'default' => function () { return new LruArrayCache; },
|
||||
],
|
||||
'region' => $regionDef,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -158,27 +198,69 @@ class S3MultiRegionClient extends BaseClient implements S3ClientInterface
|
||||
{
|
||||
parent::__construct($args);
|
||||
$this->cache = $this->getConfig('bucket_region_cache');
|
||||
|
||||
$this->getHandlerList()->prependInit(
|
||||
$this->determineRegionMiddleware(),
|
||||
'determine_region'
|
||||
);
|
||||
}
|
||||
|
||||
public function executeAsync(CommandInterface $c)
|
||||
private function determineRegionMiddleware()
|
||||
{
|
||||
return Promise\coroutine(function () use ($c) {
|
||||
if ($region = $this->cache->get($this->getCacheKey($c['Bucket']))) {
|
||||
$c = $this->getRegionalizedCommand($c, $region);
|
||||
}
|
||||
|
||||
try {
|
||||
yield parent::executeAsync($c);
|
||||
} catch (PermanentRedirectException $e) {
|
||||
if (empty($c['Bucket'])) {
|
||||
throw $e;
|
||||
return function (callable $handler) {
|
||||
return function (CommandInterface $command) use ($handler) {
|
||||
$cacheKey = $this->getCacheKey($command['Bucket']);
|
||||
if (
|
||||
empty($command['@region']) &&
|
||||
$region = $this->cache->get($cacheKey)
|
||||
) {
|
||||
$command['@region'] = $region;
|
||||
}
|
||||
$region = (yield $this->lookupBucketRegion($c['Bucket']));
|
||||
$this->cache->set($this->getCacheKey($c['Bucket']), $region);
|
||||
$c = $this->getRegionalizedCommand($c, $region);
|
||||
yield parent::executeAsync($c);
|
||||
}
|
||||
});
|
||||
|
||||
return Promise\coroutine(function () use (
|
||||
$handler,
|
||||
$command,
|
||||
$cacheKey
|
||||
) {
|
||||
try {
|
||||
yield $handler($command);
|
||||
} catch (PermanentRedirectException $e) {
|
||||
if (empty($command['Bucket'])) {
|
||||
throw $e;
|
||||
}
|
||||
$result = $e->getResult();
|
||||
$region = null;
|
||||
if (isset($result['@metadata']['headers']['x-amz-bucket-region'])) {
|
||||
$region = $result['@metadata']['headers']['x-amz-bucket-region'];
|
||||
$this->cache->set($cacheKey, $region);
|
||||
} else {
|
||||
$region = (yield $this->determineBucketRegionAsync(
|
||||
$command['Bucket']
|
||||
));
|
||||
}
|
||||
|
||||
$command['@region'] = $region;
|
||||
yield $handler($command);
|
||||
} catch (AwsException $e) {
|
||||
if ($e->getAwsErrorCode() === 'AuthorizationHeaderMalformed') {
|
||||
$region = $this->determineBucketRegionFromExceptionBody(
|
||||
$e->getResponse()->getBody()
|
||||
);
|
||||
if (!empty($region)) {
|
||||
$this->cache->set($cacheKey, $region);
|
||||
|
||||
$command['@region'] = $region;
|
||||
yield $handler($command);
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
public function createPresignedRequest(CommandInterface $command, $expires)
|
||||
@@ -211,22 +293,21 @@ class S3MultiRegionClient extends BaseClient implements S3ClientInterface
|
||||
|
||||
public function determineBucketRegionAsync($bucketName)
|
||||
{
|
||||
if ($cached = $this->cache->get($this->getCacheKey($bucketName))) {
|
||||
$cacheKey = $this->getCacheKey($bucketName);
|
||||
if ($cached = $this->cache->get($cacheKey)) {
|
||||
return Promise\promise_for($cached);
|
||||
}
|
||||
|
||||
return $this->lookupBucketRegion($bucketName)
|
||||
->then(function ($region) use ($bucketName) {
|
||||
$this->cache->set($this->getCacheKey($bucketName), $region);
|
||||
/** @var S3ClientInterface $regionalClient */
|
||||
$regionalClient = $this->getClientFromPool();
|
||||
return $regionalClient->determineBucketRegionAsync($bucketName)
|
||||
->then(
|
||||
function ($region) use ($cacheKey) {
|
||||
$this->cache->set($cacheKey, $region);
|
||||
|
||||
return $region;
|
||||
});
|
||||
}
|
||||
|
||||
private function getRegionalizedCommand(CommandInterface $command, $region)
|
||||
{
|
||||
return $this->getClientFromPool($region)
|
||||
->getCommand($command->getName(), $command->toArray());
|
||||
return $region;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private function getCacheKey($bucketName)
|
||||
|
||||
Reference in New Issue
Block a user