composer-update-patch
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
namespace Aws\S3;
|
||||
|
||||
use Aws\CommandInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
/**
|
||||
* Used to update the URL used for S3 requests to suport S3 Accelerate.
|
||||
*
|
||||
* IMPORTANT: this middleware must be added after the "build" step.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class AccelerateMiddleware
|
||||
{
|
||||
private static $exclusions = [
|
||||
'CreateBucket' => true,
|
||||
'DeleteBucket' => true,
|
||||
'ListBuckets' => true,
|
||||
];
|
||||
/** @var bool */
|
||||
private $accelerateByDefault;
|
||||
/** @var callable */
|
||||
private $nextHandler;
|
||||
|
||||
/**
|
||||
* Create a middleware wrapper function.
|
||||
*
|
||||
* @param bool $accelerateByDefault
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public static function wrap($accelerateByDefault = false)
|
||||
{
|
||||
return function (callable $handler) use ($accelerateByDefault) {
|
||||
return new self($handler, $accelerateByDefault);
|
||||
};
|
||||
}
|
||||
|
||||
public function __construct(callable $nextHandler, $accelerateByDefault = false)
|
||||
{
|
||||
$this->accelerateByDefault = (bool) $accelerateByDefault;
|
||||
$this->nextHandler = $nextHandler;
|
||||
}
|
||||
|
||||
public function __invoke(CommandInterface $command, RequestInterface $request)
|
||||
{
|
||||
if ($this->shouldAccelerate($command)) {
|
||||
$request = $request->withUri(
|
||||
$request->getUri()
|
||||
->withHost($this->getAccelerateHost($command))
|
||||
->withPath($this->getBucketlessPath(
|
||||
$request->getUri()->getPath(),
|
||||
$command
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
$nextHandler = $this->nextHandler;
|
||||
return $nextHandler($command, $request);
|
||||
}
|
||||
|
||||
private function shouldAccelerate(CommandInterface $command)
|
||||
{
|
||||
if ($this->canAccelerate($command)) {
|
||||
return isset($command['@use_accelerate_endpoint'])
|
||||
? $command['@use_accelerate_endpoint']
|
||||
: $this->accelerateByDefault;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function canAccelerate(CommandInterface $command)
|
||||
{
|
||||
return empty(self::$exclusions[$command->getName()])
|
||||
&& S3Client::isBucketDnsCompatible($command['Bucket']);
|
||||
}
|
||||
|
||||
private function getAccelerateHost(CommandInterface $command)
|
||||
{
|
||||
return "{$command['Bucket']}.s3-accelerate.amazonaws.com";
|
||||
}
|
||||
|
||||
private function getBucketlessPath($path, CommandInterface $command)
|
||||
{
|
||||
$pattern = '/^\\/' . preg_quote($command['Bucket'], '/') . '/';
|
||||
return preg_replace($pattern, '', $path) ?: '/';
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
namespace Aws\S3;
|
||||
|
||||
use Aws\CommandInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
/**
|
||||
* Dual Stack Endpoints enables customers to access AWS services with IPv6
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class DualStackMiddleware
|
||||
{
|
||||
/** @var bool */
|
||||
private $dualStackByDefault;
|
||||
/** @var string */
|
||||
private $region;
|
||||
/** @var callable */
|
||||
private $nextHandler;
|
||||
|
||||
/**
|
||||
* Create a middleware wrapper function
|
||||
*
|
||||
* @param string $region
|
||||
* @param bool $dualStackByDefault
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public static function wrap($region, $dualStackByDefault = false)
|
||||
{
|
||||
return function (callable $handler) use ($dualStackByDefault, $region) {
|
||||
return new self($handler, $region, $dualStackByDefault);
|
||||
};
|
||||
}
|
||||
|
||||
public function __construct(callable $nextHandler, $region, $dualStackByDefault = false)
|
||||
{
|
||||
$this->dualStackByDefault = (bool) $dualStackByDefault;
|
||||
$this->region = (string) $region;
|
||||
$this->nextHandler = $nextHandler;
|
||||
}
|
||||
|
||||
public function __invoke(CommandInterface $command, RequestInterface $request)
|
||||
{
|
||||
if ($this->shouldApplyDualStack($command)) {
|
||||
$request = $request->withUri(
|
||||
$request->getUri()
|
||||
->withHost($this->getDualStackHost())
|
||||
);
|
||||
}
|
||||
|
||||
$nextHandler = $this->nextHandler;
|
||||
return $nextHandler($command, $request);
|
||||
}
|
||||
|
||||
private function shouldApplyDualStack(CommandInterface $command)
|
||||
{
|
||||
return isset($command['@use_dual_stack_endpoint'])
|
||||
? $command['@use_dual_stack_endpoint']
|
||||
: $this->dualStackByDefault;
|
||||
}
|
||||
|
||||
private function getDualStackHost()
|
||||
{
|
||||
return "s3.dualstack.{$this->region}.amazonaws.com";
|
||||
}
|
||||
}
|
||||
11
vendor/aws/aws-sdk-php/src/S3/PostObjectV4.php
vendored
11
vendor/aws/aws-sdk-php/src/S3/PostObjectV4.php
vendored
@@ -4,7 +4,6 @@ namespace Aws\S3;
|
||||
use Aws\Credentials\CredentialsInterface;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use Aws\Signature\SignatureTrait;
|
||||
use Aws\Common\Enum\DateFormat;
|
||||
use Aws\Signature\SignatureV4 as SignatureV4;
|
||||
use Aws\Api\TimestampShape as TimestampShape;
|
||||
|
||||
@@ -55,6 +54,14 @@ class PostObjectV4
|
||||
'enctype' => 'multipart/form-data'
|
||||
];
|
||||
|
||||
$credentials = $this->client->getCredentials()->wait();
|
||||
$securityToken = $credentials->getSecurityToken();
|
||||
|
||||
if (null !== $securityToken) {
|
||||
array_push($options, ['x-amz-security-token' => $securityToken]);
|
||||
$formInputs['X-Amz-Security-Token'] = $securityToken;
|
||||
}
|
||||
|
||||
// setup basic policy
|
||||
$policy = [
|
||||
'expiration' => TimestampShape::format($expiration, 'iso8601'),
|
||||
@@ -65,7 +72,7 @@ class PostObjectV4
|
||||
$this->formInputs = $formInputs + ['key' => '${filename}'];
|
||||
|
||||
// finalize policy and signature
|
||||
$credentials = $this->client->getCredentials()->wait();
|
||||
|
||||
$this->formInputs += $this->getPolicyAndSignature(
|
||||
$credentials,
|
||||
$policy
|
||||
|
||||
18
vendor/aws/aws-sdk-php/src/S3/S3Client.php
vendored
18
vendor/aws/aws-sdk-php/src/S3/S3Client.php
vendored
@@ -176,8 +176,7 @@ class S3Client extends AwsClient implements S3ClientInterface
|
||||
'doc' => 'Set to true to send requests to an S3 Dual Stack'
|
||||
. ' endpoint by default, which enables IPv6 Protocol.'
|
||||
. ' Can be enabled or disabled on individual operations by setting'
|
||||
. ' \'@use_dual_stack_endpoint\' to true or false. Note:'
|
||||
. ' you cannot use it together with an accelerate endpoint.',
|
||||
. ' \'@use_dual_stack_endpoint\' to true or false.',
|
||||
'default' => false,
|
||||
],
|
||||
];
|
||||
@@ -219,17 +218,18 @@ class S3Client extends AwsClient implements S3ClientInterface
|
||||
Middleware::contentType(['PutObject', 'UploadPart']),
|
||||
's3.content_type'
|
||||
);
|
||||
|
||||
$stack->appendBuild(
|
||||
AccelerateMiddleware::wrap($this->getConfig('use_accelerate_endpoint')),
|
||||
's3.use_accelerate_endpoint'
|
||||
);
|
||||
$stack->appendBuild(
|
||||
DualStackMiddleware::wrap(
|
||||
S3EndpointMiddleware::wrap(
|
||||
$this->getRegion(),
|
||||
$this->getConfig('use_dual_stack_endpoint')
|
||||
[
|
||||
'dual_stack' => $this->getConfig('use_dual_stack_endpoint'),
|
||||
'accelerate' => $this->getConfig('use_accelerate_endpoint')
|
||||
]
|
||||
),
|
||||
's3.use_dual_stack_endpoint'
|
||||
's3.endpoint_middleware'
|
||||
);
|
||||
|
||||
// Use the bucket style middleware when using a "bucket_endpoint" (for cnames)
|
||||
if ($this->getConfig('bucket_endpoint')) {
|
||||
$stack->appendBuild(BucketEndpointMiddleware::wrap(), 's3.bucket_endpoint');
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
namespace Aws\S3;
|
||||
|
||||
use Aws\CommandInterface;
|
||||
use Aws\Exception\AwsException;
|
||||
use Aws\HandlerList;
|
||||
use Aws\ResultInterface;
|
||||
use Aws\S3\Exception\S3Exception;
|
||||
@@ -174,6 +175,12 @@ trait S3ClientTrait
|
||||
return $handler($command)
|
||||
->then(static function (ResultInterface $result) {
|
||||
return $result['@metadata']['headers']['x-amz-bucket-region'];
|
||||
}, static function (AwsException $exception) {
|
||||
$response = $exception->getResponse();
|
||||
if ($response === null) {
|
||||
throw $exception;
|
||||
}
|
||||
return $response->getHeaderLine('x-amz-bucket-region');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
161
vendor/aws/aws-sdk-php/src/S3/S3EndpointMiddleware.php
vendored
Normal file
161
vendor/aws/aws-sdk-php/src/S3/S3EndpointMiddleware.php
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
namespace Aws\S3;
|
||||
|
||||
use Aws\CommandInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
/**
|
||||
* Used to update the URL used for S3 requests to support:
|
||||
* S3 Accelerate, S3 DualStack or Both
|
||||
*
|
||||
* IMPORTANT: this middleware must be added after the "build" step.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class S3EndpointMiddleware
|
||||
{
|
||||
private static $exclusions = [
|
||||
'CreateBucket' => true,
|
||||
'DeleteBucket' => true,
|
||||
'ListBuckets' => true,
|
||||
];
|
||||
|
||||
const NO_PATTERN = 0;
|
||||
const DUALSTACK = 1;
|
||||
const ACCELERATE = 2;
|
||||
const ACCELERATE_DUALSTACK = 3;
|
||||
|
||||
/** @var bool */
|
||||
private $accelerateByDefault;
|
||||
/** @var bool */
|
||||
private $dualStackByDefault;
|
||||
/** @var string */
|
||||
private $region;
|
||||
/** @var callable */
|
||||
private $nextHandler;
|
||||
|
||||
/**
|
||||
* Create a middleware wrapper function
|
||||
*
|
||||
* @param string $region
|
||||
* @param array $options
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public static function wrap($region, array $options)
|
||||
{
|
||||
return function (callable $handler) use ($region, $options) {
|
||||
return new self($handler, $region, $options);
|
||||
};
|
||||
}
|
||||
|
||||
public function __construct(
|
||||
callable $nextHandler,
|
||||
$region,
|
||||
array $options
|
||||
) {
|
||||
$this->dualStackByDefault = isset($options['dual_stack'])
|
||||
? (bool) $options['dual_stack'] : false;
|
||||
$this->accelerateByDefault = isset($options['accelerate'])
|
||||
? (bool) $options['accelerate'] : false;
|
||||
$this->region = (string) $region;
|
||||
$this->nextHandler = $nextHandler;
|
||||
}
|
||||
|
||||
public function __invoke(CommandInterface $command, RequestInterface $request)
|
||||
{
|
||||
$endpointPattern = $this->endpointPatternDecider($command);
|
||||
switch ($endpointPattern) {
|
||||
case self::NO_PATTERN:
|
||||
break;
|
||||
case self::DUALSTACK:
|
||||
$request = $this->applyDualStackEndpoint($request);
|
||||
break;
|
||||
case self::ACCELERATE:
|
||||
$request = $this->applyAccelerateEndpoint(
|
||||
$command,
|
||||
$request,
|
||||
's3-accelerate'
|
||||
);
|
||||
break;
|
||||
case self::ACCELERATE_DUALSTACK:
|
||||
$request = $this->applyAccelerateEndpoint(
|
||||
$command,
|
||||
$request,
|
||||
's3-accelerate.dualstack'
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
$nextHandler = $this->nextHandler;
|
||||
return $nextHandler($command, $request);
|
||||
}
|
||||
|
||||
private function endpointPatternDecider(CommandInterface $command)
|
||||
{
|
||||
$accelerate = isset($command['@use_accelerate_endpoint'])
|
||||
? $command['@use_accelerate_endpoint'] : $this->accelerateByDefault;
|
||||
$dualStack = isset($command['@use_dual_stack_endpoint'])
|
||||
? $command['@use_dual_stack_endpoint'] : $this->dualStackByDefault;
|
||||
|
||||
if ($accelerate && $dualStack) {
|
||||
// When try to enable both for operations excluded from s3-accelerate,
|
||||
// only dualstack endpoints will be enabled.
|
||||
return $this->canAccelerate($command)
|
||||
? self::ACCELERATE_DUALSTACK
|
||||
: self::DUALSTACK;
|
||||
} elseif ($accelerate && $this->canAccelerate($command)) {
|
||||
return self::ACCELERATE;
|
||||
} elseif ($dualStack) {
|
||||
return self::DUALSTACK;
|
||||
}
|
||||
return self::NO_PATTERN;
|
||||
}
|
||||
|
||||
private function canAccelerate(CommandInterface $command)
|
||||
{
|
||||
return empty(self::$exclusions[$command->getName()])
|
||||
&& S3Client::isBucketDnsCompatible($command['Bucket']);
|
||||
}
|
||||
|
||||
private function applyDualStackEndpoint(RequestInterface $request)
|
||||
{
|
||||
$request = $request->withUri(
|
||||
$request->getUri()
|
||||
->withHost($this->getDualStackHost())
|
||||
);
|
||||
return $request;
|
||||
}
|
||||
|
||||
private function getDualStackHost()
|
||||
{
|
||||
return "s3.dualstack.{$this->region}.amazonaws.com";
|
||||
}
|
||||
|
||||
private function applyAccelerateEndpoint(
|
||||
CommandInterface $command,
|
||||
RequestInterface $request,
|
||||
$pattern
|
||||
) {
|
||||
$request = $request->withUri(
|
||||
$request->getUri()
|
||||
->withHost($this->getAccelerateHost($command, $pattern))
|
||||
->withPath($this->getBucketlessPath(
|
||||
$request->getUri()->getPath(),
|
||||
$command
|
||||
))
|
||||
);
|
||||
return $request;
|
||||
}
|
||||
|
||||
private function getAccelerateHost(CommandInterface $command, $pattern)
|
||||
{
|
||||
return "{$command['Bucket']}.{$pattern}.amazonaws.com";
|
||||
}
|
||||
|
||||
private function getBucketlessPath($path, CommandInterface $command)
|
||||
{
|
||||
$pattern = '/^\\/' . preg_quote($command['Bucket'], '/') . '/';
|
||||
return preg_replace($pattern, '', $path) ?: '/';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user