Laravel version update
Laravel version update
This commit is contained in:
@@ -100,7 +100,7 @@ class BatchDelete implements PromisorInterface
|
||||
array $options = []
|
||||
) {
|
||||
$fn = function (BatchDelete $that) use ($iter) {
|
||||
return \GuzzleHttp\Promise\coroutine(function () use ($that, $iter) {
|
||||
return Promise\coroutine(function () use ($that, $iter) {
|
||||
foreach ($iter as $obj) {
|
||||
if ($promise = $that->enqueue($obj)) {
|
||||
yield $promise;
|
||||
|
||||
75
vendor/aws/aws-sdk-php/src/S3/Crypto/CryptoParamsTrait.php
vendored
Normal file
75
vendor/aws/aws-sdk-php/src/S3/Crypto/CryptoParamsTrait.php
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
namespace Aws\S3\Crypto;
|
||||
|
||||
use Aws\Crypto\MaterialsProvider;
|
||||
use Aws\Crypto\MetadataEnvelope;
|
||||
use Aws\Crypto\MetadataStrategyInterface;
|
||||
|
||||
trait CryptoParamsTrait
|
||||
{
|
||||
protected function getMaterialsProvider(array $args)
|
||||
{
|
||||
if ($args['@MaterialsProvider'] instanceof MaterialsProvider) {
|
||||
return $args['@MaterialsProvider'];
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('An instance of MaterialsProvider'
|
||||
. ' must be passed in the "MaterialsProvider" field.');
|
||||
}
|
||||
|
||||
protected function getInstructionFileSuffix(array $args)
|
||||
{
|
||||
return !empty($args['@InstructionFileSuffix'])
|
||||
? $args['@InstructionFileSuffix']
|
||||
: $this->instructionFileSuffix;
|
||||
}
|
||||
|
||||
protected function determineGetObjectStrategy(
|
||||
$result,
|
||||
$instructionFileSuffix
|
||||
) {
|
||||
if (isset($result['Metadata'][MetadataEnvelope::CONTENT_KEY_V2_HEADER])) {
|
||||
return new HeadersMetadataStrategy();
|
||||
}
|
||||
|
||||
return new InstructionFileMetadataStrategy(
|
||||
$this->client,
|
||||
$instructionFileSuffix
|
||||
);
|
||||
}
|
||||
|
||||
protected function getMetadataStrategy(array $args, $instructionFileSuffix)
|
||||
{
|
||||
if (!empty($args['@MetadataStrategy'])) {
|
||||
if ($args['@MetadataStrategy'] instanceof MetadataStrategyInterface) {
|
||||
return $args['@MetadataStrategy'];
|
||||
}
|
||||
|
||||
if (is_string($args['@MetadataStrategy'])) {
|
||||
switch ($args['@MetadataStrategy']) {
|
||||
case HeadersMetadataStrategy::class:
|
||||
return new HeadersMetadataStrategy();
|
||||
case InstructionFileMetadataStrategy::class:
|
||||
return new InstructionFileMetadataStrategy(
|
||||
$this->client,
|
||||
$instructionFileSuffix
|
||||
);
|
||||
default:
|
||||
throw new \InvalidArgumentException('Could not match the'
|
||||
. ' specified string in "MetadataStrategy" to a'
|
||||
. ' predefined strategy.');
|
||||
}
|
||||
} else {
|
||||
throw new \InvalidArgumentException('The metadata strategy that'
|
||||
. ' was passed to "MetadataStrategy" was unrecognized.');
|
||||
}
|
||||
} elseif ($instructionFileSuffix) {
|
||||
return new InstructionFileMetadataStrategy(
|
||||
$this->client,
|
||||
$instructionFileSuffix
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
52
vendor/aws/aws-sdk-php/src/S3/Crypto/HeadersMetadataStrategy.php
vendored
Normal file
52
vendor/aws/aws-sdk-php/src/S3/Crypto/HeadersMetadataStrategy.php
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
namespace Aws\S3\Crypto;
|
||||
|
||||
use \Aws\Crypto\MetadataStrategyInterface;
|
||||
use \Aws\Crypto\MetadataEnvelope;
|
||||
|
||||
class HeadersMetadataStrategy implements MetadataStrategyInterface
|
||||
{
|
||||
/**
|
||||
* Places the information in the MetadataEnvelope in to the Meatadata for
|
||||
* the PutObject request of the encrypted object.
|
||||
*
|
||||
* @param MetadataEnvelope $envelope Encryption data to save according to
|
||||
* the strategy.
|
||||
* @param array $args Arguments for PutObject that can be manipulated to
|
||||
* store strategy related information.
|
||||
*
|
||||
* @return array Updated arguments for PutObject.
|
||||
*/
|
||||
public function save(MetadataEnvelope $envelope, array $args)
|
||||
{
|
||||
foreach ($envelope as $header=>$value) {
|
||||
$args['Metadata'][$header] = $value;
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a MetadataEnvelope according to the Metadata headers from the
|
||||
* GetObject result.
|
||||
*
|
||||
* @param array $args Arguments from Command and Result that contains
|
||||
* S3 Object information, relevant headers, and command
|
||||
* configuration.
|
||||
*
|
||||
* @return MetadataEnvelope
|
||||
*/
|
||||
public function load(array $args)
|
||||
{
|
||||
$envelope = new MetadataEnvelope();
|
||||
$constantValues = MetadataEnvelope::getConstantValues();
|
||||
|
||||
foreach ($constantValues as $constant) {
|
||||
if (!empty($args['Metadata'][$constant])) {
|
||||
$envelope[$constant] = $args['Metadata'][$constant];
|
||||
}
|
||||
}
|
||||
|
||||
return $envelope;
|
||||
}
|
||||
}
|
||||
90
vendor/aws/aws-sdk-php/src/S3/Crypto/InstructionFileMetadataStrategy.php
vendored
Normal file
90
vendor/aws/aws-sdk-php/src/S3/Crypto/InstructionFileMetadataStrategy.php
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
namespace Aws\S3\Crypto;
|
||||
|
||||
use \Aws\Crypto\MetadataStrategyInterface;
|
||||
use \Aws\Crypto\MetadataEnvelope;
|
||||
use \Aws\S3\S3Client;
|
||||
|
||||
/**
|
||||
* Stores and reads encryption MetadataEnvelope information in a file on Amazon
|
||||
* S3.
|
||||
*
|
||||
* A file with the contents of a MetadataEnvelope will be created or read from
|
||||
* alongside the base file on Amazon S3. The provided client will be used for
|
||||
* reading or writing this object. A specified suffix (default of '.instruction'
|
||||
* will be applied to each of the operations involved with the instruction file.
|
||||
*
|
||||
* If there is a failure after an instruction file has been uploaded, it will
|
||||
* not be automatically deleted.
|
||||
*/
|
||||
class InstructionFileMetadataStrategy implements MetadataStrategyInterface
|
||||
{
|
||||
const DEFAULT_FILE_SUFFIX = '.instruction';
|
||||
|
||||
private $client;
|
||||
private $suffix;
|
||||
|
||||
/**
|
||||
* @param S3Client $client Client for use in uploading the instruction file.
|
||||
* @param string|null $suffix Optional override suffix for instruction file
|
||||
* object keys.
|
||||
*/
|
||||
public function __construct(S3Client $client, $suffix = null)
|
||||
{
|
||||
$this->suffix = empty($suffix)
|
||||
? self::DEFAULT_FILE_SUFFIX
|
||||
: $suffix;
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Places the information in the MetadataEnvelope to a location on S3.
|
||||
*
|
||||
* @param MetadataEnvelope $envelope Encryption data to save according to
|
||||
* the strategy.
|
||||
* @param array $args Starting arguments for PutObject, used for saving
|
||||
* extra the instruction file.
|
||||
*
|
||||
* @return array Updated arguments for PutObject.
|
||||
*/
|
||||
public function save(MetadataEnvelope $envelope, array $args)
|
||||
{
|
||||
$this->client->putObject([
|
||||
'Bucket' => $args['Bucket'],
|
||||
'Key' => $args['Key'] . $this->suffix,
|
||||
'Body' => json_encode($envelope)
|
||||
]);
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the strategy's client to retrieve the instruction file from S3 and generates
|
||||
* a MetadataEnvelope from its contents.
|
||||
*
|
||||
* @param array $args Arguments from Command and Result that contains
|
||||
* S3 Object information, relevant headers, and command
|
||||
* configuration.
|
||||
*
|
||||
* @return MetadataEnvelope
|
||||
*/
|
||||
public function load(array $args)
|
||||
{
|
||||
$result = $this->client->getObject([
|
||||
'Bucket' => $args['Bucket'],
|
||||
'Key' => $args['Key'] . $this->suffix
|
||||
]);
|
||||
|
||||
$metadataHeaders = json_decode($result['Body'], true);
|
||||
$envelope = new MetadataEnvelope();
|
||||
$constantValues = MetadataEnvelope::getConstantValues();
|
||||
|
||||
foreach ($constantValues as $constant) {
|
||||
if (!empty($metadataHeaders[$constant])) {
|
||||
$envelope[$constant] = $metadataHeaders[$constant];
|
||||
}
|
||||
}
|
||||
|
||||
return $envelope;
|
||||
}
|
||||
}
|
||||
317
vendor/aws/aws-sdk-php/src/S3/Crypto/S3EncryptionClient.php
vendored
Normal file
317
vendor/aws/aws-sdk-php/src/S3/Crypto/S3EncryptionClient.php
vendored
Normal file
@@ -0,0 +1,317 @@
|
||||
<?php
|
||||
namespace Aws\S3\Crypto;
|
||||
|
||||
use Aws\HashingStream;
|
||||
use Aws\PhpHash;
|
||||
use Aws\Crypto\AbstractCryptoClient;
|
||||
use Aws\Crypto\EncryptionTrait;
|
||||
use Aws\Crypto\DecryptionTrait;
|
||||
use Aws\Crypto\MetadataEnvelope;
|
||||
use Aws\Crypto\MaterialsProvider;
|
||||
use Aws\Crypto\Cipher\CipherBuilderTrait;
|
||||
use Aws\S3\S3Client;
|
||||
use GuzzleHttp\Promise;
|
||||
use GuzzleHttp\Promise\PromiseInterface;
|
||||
use GuzzleHttp\Psr7;
|
||||
|
||||
/**
|
||||
* Provides a wrapper for an S3Client that supplies functionality to encrypt
|
||||
* data on putObject[Async] calls and decrypt data on getObject[Async] calls.
|
||||
*/
|
||||
class S3EncryptionClient extends AbstractCryptoClient
|
||||
{
|
||||
use EncryptionTrait, DecryptionTrait, CipherBuilderTrait, CryptoParamsTrait;
|
||||
|
||||
private $client;
|
||||
private $instructionFileSuffix;
|
||||
|
||||
/**
|
||||
* @param S3Client $client The S3Client to be used for true uploading and
|
||||
* retrieving objects from S3 when using the
|
||||
* encryption client.
|
||||
* @param string|null $instructionFileSuffix Suffix for a client wide
|
||||
* default when using instruction
|
||||
* files for metadata storage.
|
||||
*/
|
||||
public function __construct(
|
||||
S3Client $client,
|
||||
$instructionFileSuffix = null
|
||||
) {
|
||||
$this->client = $client;
|
||||
$this->instructionFileSuffix = $instructionFileSuffix;
|
||||
}
|
||||
|
||||
private static function getDefaultStrategy()
|
||||
{
|
||||
return new HeadersMetadataStrategy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypts the data in the 'Body' field of $args and promises to upload it
|
||||
* to the specified location on S3.
|
||||
*
|
||||
* @param array $args Arguments for encrypting an object and uploading it
|
||||
* to S3 via PutObject.
|
||||
*
|
||||
* The required configuration arguments are as follows:
|
||||
*
|
||||
* - @MaterialsProvider: (MaterialsProvider) Provides Cek, Iv, and Cek
|
||||
* encrypting/decrypting for encryption metadata.
|
||||
* - @CipherOptions: (array) Cipher options for encrypting data. Only the
|
||||
* Cipher option is required. Accepts the following:
|
||||
* - Cipher: (string) cbc|gcm
|
||||
* See also: AbstractCryptoClient::$supportedCiphers
|
||||
* - KeySize: (int) 128|192|256
|
||||
* See also: MaterialsProvider::$supportedKeySizes
|
||||
* - Aad: (string) Additional authentication data. This option is
|
||||
* passed directly to OpenSSL when using gcm. It is ignored when
|
||||
* using cbc.
|
||||
*
|
||||
* The optional configuration arguments are as follows:
|
||||
*
|
||||
* - @MetadataStrategy: (MetadataStrategy|string|null) Strategy for storing
|
||||
* MetadataEnvelope information. Defaults to using a
|
||||
* HeadersMetadataStrategy. Can either be a class implementing
|
||||
* MetadataStrategy, a class name of a predefined strategy, or empty/null
|
||||
* to default.
|
||||
* - @InstructionFileSuffix: (string|null) Suffix used when writing to an
|
||||
* instruction file if using an InstructionFileMetadataHandler.
|
||||
*
|
||||
* @return PromiseInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException Thrown when arguments above are not
|
||||
* passed or are passed incorrectly.
|
||||
*/
|
||||
public function putObjectAsync(array $args)
|
||||
{
|
||||
$provider = $this->getMaterialsProvider($args);
|
||||
unset($args['@MaterialsProvider']);
|
||||
|
||||
$instructionFileSuffix = $this->getInstructionFileSuffix($args);
|
||||
unset($args['@InstructionFileSuffix']);
|
||||
|
||||
$strategy = $this->getMetadataStrategy($args, $instructionFileSuffix);
|
||||
unset($args['@MetadataStrategy']);
|
||||
|
||||
$envelope = new MetadataEnvelope();
|
||||
|
||||
return Promise\promise_for($this->encrypt(
|
||||
Psr7\stream_for($args['Body']),
|
||||
$args['@CipherOptions'] ?: [],
|
||||
$provider,
|
||||
$envelope
|
||||
))->then(
|
||||
function ($encryptedBodyStream) use ($args) {
|
||||
$hash = new PhpHash('sha256');
|
||||
$hashingEncryptedBodyStream = new HashingStream(
|
||||
$encryptedBodyStream,
|
||||
$hash,
|
||||
self::getContentShaDecorator($args)
|
||||
);
|
||||
return [$hashingEncryptedBodyStream, $args];
|
||||
}
|
||||
)->then(
|
||||
function ($putObjectContents) use ($strategy, $envelope) {
|
||||
list($bodyStream, $args) = $putObjectContents;
|
||||
if ($strategy === null) {
|
||||
$strategy = self::getDefaultStrategy();
|
||||
}
|
||||
|
||||
$updatedArgs = $strategy->save($envelope, $args);
|
||||
$updatedArgs['Body'] = $bodyStream;
|
||||
return $updatedArgs;
|
||||
}
|
||||
)->then(
|
||||
function ($args) {
|
||||
unset($args['@CipherOptions']);
|
||||
return $this->client->putObjectAsync($args);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private static function getContentShaDecorator(&$args)
|
||||
{
|
||||
return function ($hash) use (&$args) {
|
||||
$args['ContentSHA256'] = bin2hex($hash);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypts the data in the 'Body' field of $args and uploads it to the
|
||||
* specified location on S3.
|
||||
*
|
||||
* @param array $args Arguments for encrypting an object and uploading it
|
||||
* to S3 via PutObject.
|
||||
*
|
||||
* The required configuration arguments are as follows:
|
||||
*
|
||||
* - @MaterialsProvider: (MaterialsProvider) Provides Cek, Iv, and Cek
|
||||
* encrypting/decrypting for encryption metadata.
|
||||
* - @CipherOptions: (array) Cipher options for encrypting data. A Cipher
|
||||
* is required. Accepts the following options:
|
||||
* - Cipher: (string) cbc|gcm
|
||||
* See also: AbstractCryptoClient::$supportedCiphers
|
||||
* - KeySize: (int) 128|192|256
|
||||
* See also: MaterialsProvider::$supportedKeySizes
|
||||
* - Aad: (string) Additional authentication data. This option is
|
||||
* passed directly to OpenSSL when using gcm. It is ignored when
|
||||
* using cbc.
|
||||
*
|
||||
* The optional configuration arguments are as follows:
|
||||
*
|
||||
* - @MetadataStrategy: (MetadataStrategy|string|null) Strategy for storing
|
||||
* MetadataEnvelope information. Defaults to using a
|
||||
* HeadersMetadataStrategy. Can either be a class implementing
|
||||
* MetadataStrategy, a class name of a predefined strategy, or empty/null
|
||||
* to default.
|
||||
* - @InstructionFileSuffix: (string|null) Suffix used when writing to an
|
||||
* instruction file if an using an InstructionFileMetadataHandler was
|
||||
* determined.
|
||||
*
|
||||
* @return \Aws\Result PutObject call result with the details of uploading
|
||||
* the encrypted file.
|
||||
*
|
||||
* @throws \InvalidArgumentException Thrown when arguments above are not
|
||||
* passed or are passed incorrectly.
|
||||
*/
|
||||
public function putObject(array $args)
|
||||
{
|
||||
return $this->putObjectAsync($args)->wait();
|
||||
}
|
||||
|
||||
/**
|
||||
* Promises to retrieve an object from S3 and decrypt the data in the
|
||||
* 'Body' field.
|
||||
*
|
||||
* @param array $args Arguments for retrieving an object from S3 via
|
||||
* GetObject and decrypting it.
|
||||
*
|
||||
* The required configuration argument is as follows:
|
||||
*
|
||||
* - @MaterialsProvider: (MaterialsProvider) Provides Cek, Iv, and Cek
|
||||
* encrypting/decrypting for decryption metadata. May have data loaded
|
||||
* from the MetadataEnvelope upon decryption.
|
||||
*
|
||||
* The optional configuration arguments are as follows:
|
||||
*
|
||||
* - SaveAs: (string) The path to a file on disk to save the decrypted
|
||||
* object data. This will be handled by file_put_contents instead of the
|
||||
* Guzzle sink.
|
||||
*
|
||||
* - @MetadataStrategy: (MetadataStrategy|string|null) Strategy for reading
|
||||
* MetadataEnvelope information. Defaults to determining based on object
|
||||
* response headers. Can either be a class implementing MetadataStrategy,
|
||||
* a class name of a predefined strategy, or empty/null to default.
|
||||
* - @InstructionFileSuffix: (string) Suffix used when looking for an
|
||||
* instruction file if an InstructionFileMetadataHandler is being used.
|
||||
* - @CipherOptions: (array) Cipher options for decrypting data. A Cipher
|
||||
* is required. Accepts the following options:
|
||||
* - Aad: (string) Additional authentication data. This option is
|
||||
* passed directly to OpenSSL when using gcm. It is ignored when
|
||||
* using cbc.
|
||||
*
|
||||
* @return PromiseInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException Thrown when required arguments are not
|
||||
* passed or are passed incorrectly.
|
||||
*/
|
||||
public function getObjectAsync(array $args)
|
||||
{
|
||||
$provider = $this->getMaterialsProvider($args);
|
||||
unset($args['@MaterialsProvider']);
|
||||
|
||||
$instructionFileSuffix = $this->getInstructionFileSuffix($args);
|
||||
unset($args['@InstructionFileSuffix']);
|
||||
|
||||
$strategy = $this->getMetadataStrategy($args, $instructionFileSuffix);
|
||||
unset($args['@MetadataStrategy']);
|
||||
|
||||
$saveAs = null;
|
||||
if (!empty($args['SaveAs'])) {
|
||||
$saveAs = $args['SaveAs'];
|
||||
}
|
||||
|
||||
$promise = $this->client->getObjectAsync($args)
|
||||
->then(
|
||||
function ($result) use (
|
||||
$provider,
|
||||
$instructionFileSuffix,
|
||||
$strategy,
|
||||
$args
|
||||
) {
|
||||
if ($strategy === null) {
|
||||
$strategy = $this->determineGetObjectStrategy(
|
||||
$result,
|
||||
$instructionFileSuffix
|
||||
);
|
||||
}
|
||||
|
||||
$envelope = $strategy->load($args + [
|
||||
'Metadata' => $result['Metadata']
|
||||
]);
|
||||
|
||||
$provider = $provider->fromDecryptionEnvelope($envelope);
|
||||
|
||||
$result['Body'] = $this->decrypt(
|
||||
$result['Body'],
|
||||
$provider,
|
||||
$envelope,
|
||||
isset($args['@CipherOptions'])
|
||||
? $args['@CipherOptions']
|
||||
: []
|
||||
);
|
||||
return $result;
|
||||
}
|
||||
)->then(
|
||||
function ($result) use ($saveAs) {
|
||||
if (!empty($saveAs)) {
|
||||
file_put_contents(
|
||||
$saveAs,
|
||||
(string)$result['Body'],
|
||||
LOCK_EX
|
||||
);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
);
|
||||
|
||||
return $promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an object from S3 and decrypts the data in the 'Body' field.
|
||||
*
|
||||
* @param array $args Arguments for retrieving an object from S3 via
|
||||
* GetObject and decrypting it.
|
||||
*
|
||||
* The required configuration argument is as follows:
|
||||
*
|
||||
* - @MaterialsProvider: (MaterialsProvider) Provides Cek, Iv, and Cek
|
||||
* encrypting/decrypting for decryption metadata. May have data loaded
|
||||
* from the MetadataEnvelope upon decryption.
|
||||
*
|
||||
* The optional configuration arguments are as follows:
|
||||
*
|
||||
* - SaveAs: (string) The path to a file on disk to save the decrypted
|
||||
* object data. This will be handled by file_put_contents instead of the
|
||||
* Guzzle sink.
|
||||
* - @InstructionFileSuffix: (string|null) Suffix used when looking for an
|
||||
* instruction file if an InstructionFileMetadataHandler was detected.
|
||||
* - @CipherOptions: (array) Cipher options for encrypting data. A Cipher
|
||||
* is required. Accepts the following options:
|
||||
* - Aad: (string) Additional authentication data. This option is
|
||||
* passed directly to OpenSSL when using gcm. It is ignored when
|
||||
* using cbc.
|
||||
*
|
||||
* @return \Aws\Result GetObject call result with the 'Body' field
|
||||
* wrapped in a decryption stream with its metadata
|
||||
* information.
|
||||
*
|
||||
* @throws \InvalidArgumentException Thrown when arguments above are not
|
||||
* passed or are passed incorrectly.
|
||||
*/
|
||||
public function getObject(array $args)
|
||||
{
|
||||
return $this->getObjectAsync($args)->wait();
|
||||
}
|
||||
}
|
||||
157
vendor/aws/aws-sdk-php/src/S3/Crypto/S3EncryptionMultipartUploader.php
vendored
Normal file
157
vendor/aws/aws-sdk-php/src/S3/Crypto/S3EncryptionMultipartUploader.php
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
namespace Aws\S3\Crypto;
|
||||
|
||||
use Aws\Crypto\AbstractCryptoClient;
|
||||
use Aws\Crypto\EncryptionTrait;
|
||||
use Aws\Crypto\MetadataEnvelope;
|
||||
use Aws\Crypto\Cipher\CipherBuilderTrait;
|
||||
use Aws\S3\MultipartUploader;
|
||||
use Aws\S3\S3ClientInterface;
|
||||
use GuzzleHttp\Promise;
|
||||
|
||||
/**
|
||||
* Encapsulates the execution of a multipart upload of an encrypted object to S3.
|
||||
*/
|
||||
class S3EncryptionMultipartUploader extends MultipartUploader
|
||||
{
|
||||
use EncryptionTrait, CipherBuilderTrait, CryptoParamsTrait;
|
||||
|
||||
/**
|
||||
* Returns if the passed cipher name is supported for encryption by the SDK.
|
||||
*
|
||||
* @param string $cipherName The name of a cipher to verify is registered.
|
||||
*
|
||||
* @return bool If the cipher passed is in our supported list.
|
||||
*/
|
||||
public static function isSupportedCipher($cipherName)
|
||||
{
|
||||
return in_array($cipherName, AbstractCryptoClient::$supportedCiphers);
|
||||
}
|
||||
|
||||
private $provider;
|
||||
private $instructionFileSuffix;
|
||||
private $strategy;
|
||||
|
||||
/**
|
||||
* Creates a multipart upload for an S3 object after encrypting it.
|
||||
*
|
||||
* The required configuration options are as follows:
|
||||
*
|
||||
* - @MaterialsProvider: (MaterialsProvider) Provides Cek, Iv, and Cek
|
||||
* encrypting/decrypting for encryption metadata.
|
||||
* - @CipherOptions: (array) Cipher options for encrypting data. A Cipher
|
||||
* is required. Accepts the following options:
|
||||
* - Cipher: (string) cbc|gcm
|
||||
* See also: AbstractCryptoClient::$supportedCiphers
|
||||
* - KeySize: (int) 128|192|256
|
||||
* See also: MaterialsProvider::$supportedKeySizes
|
||||
* - Aad: (string) Additional authentication data. This option is
|
||||
* passed directly to OpenSSL when using gcm. It is ignored when
|
||||
* using cbc.
|
||||
* - bucket: (string) Name of the bucket to which the object is
|
||||
* being uploaded.
|
||||
* - key: (string) Key to use for the object being uploaded.
|
||||
*
|
||||
* The optional configuration arguments are as follows:
|
||||
*
|
||||
* - @MetadataStrategy: (MetadataStrategy|string|null) Strategy for storing
|
||||
* MetadataEnvelope information. Defaults to using a
|
||||
* HeadersMetadataStrategy. Can either be a class implementing
|
||||
* MetadataStrategy, a class name of a predefined strategy, or empty/null
|
||||
* to default.
|
||||
* - @InstructionFileSuffix: (string|null) Suffix used when writing to an
|
||||
* instruction file if an using an InstructionFileMetadataHandler was
|
||||
* determined.
|
||||
* - acl: (string) ACL to set on the object being upload. Objects are
|
||||
* private by default.
|
||||
* - before_complete: (callable) Callback to invoke before the
|
||||
* `CompleteMultipartUpload` operation. The callback should have a
|
||||
* function signature like `function (Aws\Command $command) {...}`.
|
||||
* - before_initiate: (callable) Callback to invoke before the
|
||||
* `CreateMultipartUpload` operation. The callback should have a function
|
||||
* signature like `function (Aws\Command $command) {...}`.
|
||||
* - before_upload: (callable) Callback to invoke before any `UploadPart`
|
||||
* operations. The callback should have a function signature like
|
||||
* `function (Aws\Command $command) {...}`.
|
||||
* - concurrency: (int, default=int(5)) Maximum number of concurrent
|
||||
* `UploadPart` operations allowed during the multipart upload.
|
||||
* - params: (array) An array of key/value parameters that will be applied
|
||||
* to each of the sub-commands run by the uploader as a base.
|
||||
* Auto-calculated options will override these parameters. If you need
|
||||
* more granularity over parameters to each sub-command, use the before_*
|
||||
* options detailed above to update the commands directly.
|
||||
* - part_size: (int, default=int(5242880)) Part size, in bytes, to use when
|
||||
* doing a multipart upload. This must between 5 MB and 5 GB, inclusive.
|
||||
* - state: (Aws\Multipart\UploadState) An object that represents the state
|
||||
* of the multipart upload and that is used to resume a previous upload.
|
||||
* When this option is provided, the `bucket`, `key`, and `part_size`
|
||||
* options are ignored.
|
||||
*
|
||||
* @param S3ClientInterface $client Client used for the upload.
|
||||
* @param mixed $source Source of the data to upload.
|
||||
* @param array $config Configuration used to perform the upload.
|
||||
*/
|
||||
public function __construct(
|
||||
S3ClientInterface $client,
|
||||
$source,
|
||||
array $config = []
|
||||
) {
|
||||
$this->client = $client;
|
||||
$config['params'] = [];
|
||||
if (!empty($config['bucket'])) {
|
||||
$config['params']['Bucket'] = $config['bucket'];
|
||||
}
|
||||
if (!empty($config['key'])) {
|
||||
$config['params']['Key'] = $config['key'];
|
||||
}
|
||||
|
||||
$this->provider = $this->getMaterialsProvider($config);
|
||||
unset($config['@MaterialsProvider']);
|
||||
|
||||
$this->instructionFileSuffix = $this->getInstructionFileSuffix($config);
|
||||
unset($config['@InstructionFileSuffix']);
|
||||
$this->strategy = $this->getMetadataStrategy(
|
||||
$config,
|
||||
$this->instructionFileSuffix
|
||||
);
|
||||
if ($this->strategy === null) {
|
||||
$this->strategy = self::getDefaultStrategy();
|
||||
}
|
||||
unset($config['@MetadataStrategy']);
|
||||
|
||||
$config['prepare_data_source'] = $this->getEncryptingDataPreparer();
|
||||
|
||||
parent::__construct($client, $source, $config);
|
||||
}
|
||||
|
||||
private static function getDefaultStrategy()
|
||||
{
|
||||
return new HeadersMetadataStrategy();
|
||||
}
|
||||
|
||||
private function getEncryptingDataPreparer()
|
||||
{
|
||||
return function() {
|
||||
// Defer encryption work until promise is executed
|
||||
$envelope = new MetadataEnvelope();
|
||||
|
||||
list($this->source, $params) = Promise\promise_for($this->encrypt(
|
||||
$this->source,
|
||||
$this->config['@cipheroptions'] ?: [],
|
||||
$this->provider,
|
||||
$envelope
|
||||
))->then(
|
||||
function ($bodyStream) use ($envelope) {
|
||||
$params = $this->strategy->save(
|
||||
$envelope,
|
||||
$this->config['params']
|
||||
);
|
||||
return [$bodyStream, $params];
|
||||
}
|
||||
)->wait();
|
||||
|
||||
$this->source->rewind();
|
||||
$this->config['params'] = $params;
|
||||
};
|
||||
}
|
||||
}
|
||||
84
vendor/aws/aws-sdk-php/src/S3/Exception/S3MultipartUploadException.php
vendored
Normal file
84
vendor/aws/aws-sdk-php/src/S3/Exception/S3MultipartUploadException.php
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
namespace Aws\S3\Exception;
|
||||
|
||||
use Aws\CommandInterface;
|
||||
use Aws\Exception\AwsException;
|
||||
use Aws\Multipart\UploadState;
|
||||
|
||||
class S3MultipartUploadException extends \Aws\Exception\MultipartUploadException
|
||||
{
|
||||
/** @var string Bucket of the transfer object */
|
||||
private $bucket;
|
||||
/** @var string Key of the transfer object */
|
||||
private $key;
|
||||
/** @var string Source file name of the transfer object */
|
||||
private $filename;
|
||||
|
||||
/**
|
||||
* @param UploadState $state Upload state at time of the exception.
|
||||
* @param \Exception|array $prev Exception being thrown. Could be an array of
|
||||
* AwsExceptions being thrown when uploading parts
|
||||
* for one object, or an instance of AwsException
|
||||
* for a specific Multipart error being thrown in
|
||||
* the MultipartUpload process.
|
||||
*/
|
||||
public function __construct(UploadState $state, $prev = null) {
|
||||
if (is_array($prev) && $error = $prev[key($prev)]) {
|
||||
$this->collectPathInfo($error->getCommand());
|
||||
} elseif ($prev instanceof AwsException) {
|
||||
$this->collectPathInfo($prev->getCommand());
|
||||
}
|
||||
parent::__construct($state, $prev);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Bucket information of the transfer object
|
||||
*
|
||||
* @return string|null Returns null when 'Bucket' information
|
||||
* is unavailable.
|
||||
*/
|
||||
public function getBucket()
|
||||
{
|
||||
return $this->bucket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Key information of the transfer object
|
||||
*
|
||||
* @return string|null Returns null when 'Key' information
|
||||
* is unavailable.
|
||||
*/
|
||||
public function getKey()
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source file name of the transfer object
|
||||
*
|
||||
* @return string|null Returns null when metadata of the stream
|
||||
* wrapped in 'Body' parameter is unavailable.
|
||||
*/
|
||||
public function getSourceFileName()
|
||||
{
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect file path information when accessible. (Bucket, Key)
|
||||
*
|
||||
* @param CommandInterface $cmd
|
||||
*/
|
||||
private function collectPathInfo(CommandInterface $cmd)
|
||||
{
|
||||
if (empty($this->bucket) && isset($cmd['Bucket'])) {
|
||||
$this->bucket = $cmd['Bucket'];
|
||||
}
|
||||
if (empty($this->key) && isset($cmd['Key'])) {
|
||||
$this->key = $cmd['Key'];
|
||||
}
|
||||
if (empty($this->filename) && isset($cmd['Body'])) {
|
||||
$this->filename = $cmd['Body']->getMetadata('uri');
|
||||
}
|
||||
}
|
||||
}
|
||||
29
vendor/aws/aws-sdk-php/src/S3/MultipartCopy.php
vendored
29
vendor/aws/aws-sdk-php/src/S3/MultipartCopy.php
vendored
@@ -35,6 +35,11 @@ class MultipartCopy extends AbstractUploadManager
|
||||
* - concurrency: (int, default=int(5)) Maximum number of concurrent
|
||||
* `UploadPart` operations allowed during the multipart upload.
|
||||
* - key: (string, required) Key to use for the object being uploaded.
|
||||
* - params: (array) An array of key/value parameters that will be applied
|
||||
* to each of the sub-commands run by the uploader as a base.
|
||||
* Auto-calculated options will override these parameters. If you need
|
||||
* more granularity over parameters to each sub-command, use the before_*
|
||||
* options detailed above to update the commands directly.
|
||||
* - part_size: (int, default=int(5242880)) Part size, in bytes, to use when
|
||||
* doing a multipart upload. This must between 5 MB and 5 GB, inclusive.
|
||||
* - state: (Aws\Multipart\UploadState) An object that represents the state
|
||||
@@ -107,19 +112,27 @@ class MultipartCopy extends AbstractUploadManager
|
||||
|
||||
private function createPart($partNumber, $partsCount)
|
||||
{
|
||||
$data = [];
|
||||
|
||||
// Apply custom params to UploadPartCopy data
|
||||
$config = $this->getConfig();
|
||||
$params = isset($config['params']) ? $config['params'] : [];
|
||||
foreach ($params as $k => $v) {
|
||||
$data[$k] = $v;
|
||||
}
|
||||
|
||||
$data['CopySource'] = $this->source;
|
||||
$data['PartNumber'] = $partNumber;
|
||||
|
||||
$defaultPartSize = $this->determinePartSize();
|
||||
$startByte = $defaultPartSize * ($partNumber - 1);
|
||||
$partSize = $partNumber < $partsCount
|
||||
$data['ContentLength'] = $partNumber < $partsCount
|
||||
? $defaultPartSize
|
||||
: $this->getSourceSize() - ($defaultPartSize * ($partsCount - 1));
|
||||
$endByte = $startByte + $partSize - 1;
|
||||
$endByte = $startByte + $data['ContentLength'] - 1;
|
||||
$data['CopySourceRange'] = "bytes=$startByte-$endByte";
|
||||
|
||||
return [
|
||||
'ContentLength' => $partSize,
|
||||
'CopySource' => $this->source,
|
||||
'CopySourceRange' => "bytes=$startByte-$endByte",
|
||||
'PartNumber' => $partNumber,
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function extractETag(ResultInterface $result)
|
||||
|
||||
@@ -7,6 +7,7 @@ use Aws\PhpHash;
|
||||
use Aws\ResultInterface;
|
||||
use GuzzleHttp\Psr7;
|
||||
use Psr\Http\Message\StreamInterface as Stream;
|
||||
use Aws\S3\Exception\S3MultipartUploadException;
|
||||
|
||||
/**
|
||||
* Encapsulates the execution of a multipart upload to S3 or Glacier.
|
||||
@@ -40,8 +41,16 @@ class MultipartUploader extends AbstractUploader
|
||||
* - concurrency: (int, default=int(5)) Maximum number of concurrent
|
||||
* `UploadPart` operations allowed during the multipart upload.
|
||||
* - key: (string, required) Key to use for the object being uploaded.
|
||||
* - params: (array) An array of key/value parameters that will be applied
|
||||
* to each of the sub-commands run by the uploader as a base.
|
||||
* Auto-calculated options will override these parameters. If you need
|
||||
* more granularity over parameters to each sub-command, use the before_*
|
||||
* options detailed above to update the commands directly.
|
||||
* - part_size: (int, default=int(5242880)) Part size, in bytes, to use when
|
||||
* doing a multipart upload. This must between 5 MB and 5 GB, inclusive.
|
||||
* - prepare_data_source: (callable) Callback to invoke before starting the
|
||||
* multipart upload workflow. The callback should have a function
|
||||
* signature like `function () {...}`.
|
||||
* - state: (Aws\Multipart\UploadState) An object that represents the state
|
||||
* of the multipart upload and that is used to resume a previous upload.
|
||||
* When this option is provided, the `bucket`, `key`, and `part_size`
|
||||
@@ -59,6 +68,7 @@ class MultipartUploader extends AbstractUploader
|
||||
parent::__construct($client, $source, array_change_key_case($config) + [
|
||||
'bucket' => null,
|
||||
'key' => null,
|
||||
'exception_class' => S3MultipartUploadException::class,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -82,7 +92,16 @@ class MultipartUploader extends AbstractUploader
|
||||
protected function createPart($seekable, $number)
|
||||
{
|
||||
// Initialize the array of part data that will be returned.
|
||||
$data = ['PartNumber' => $number];
|
||||
$data = [];
|
||||
|
||||
// Apply custom params to UploadPart data
|
||||
$config = $this->getConfig();
|
||||
$params = isset($config['params']) ? $config['params'] : [];
|
||||
foreach ($params as $k => $v) {
|
||||
$data[$k] = $v;
|
||||
}
|
||||
|
||||
$data['PartNumber'] = $number;
|
||||
|
||||
// Read from the source to create the body stream.
|
||||
if ($seekable) {
|
||||
@@ -96,16 +115,18 @@ class MultipartUploader extends AbstractUploader
|
||||
$source = $this->decorateWithHashes($source, $data);
|
||||
$body = Psr7\stream_for();
|
||||
Psr7\copy_to_stream($source, $body);
|
||||
$data['ContentLength'] = $body->getSize();
|
||||
}
|
||||
|
||||
$contentLength = $body->getSize();
|
||||
|
||||
// Do not create a part if the body size is zero.
|
||||
if ($body->getSize() === 0) {
|
||||
if ($contentLength === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$body->seek(0);
|
||||
$data['Body'] = $body;
|
||||
$data['ContentLength'] = $contentLength;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -61,9 +61,14 @@ trait MultipartUploadingTrait
|
||||
|
||||
protected function getCompleteParams()
|
||||
{
|
||||
return ['MultipartUpload' => [
|
||||
$config = $this->getConfig();
|
||||
$params = isset($config['params']) ? $config['params'] : [];
|
||||
|
||||
$params['MultipartUpload'] = [
|
||||
'Parts' => $this->getState()->getUploadedParts()
|
||||
]];
|
||||
];
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
protected function determinePartSize()
|
||||
@@ -90,14 +95,15 @@ trait MultipartUploadingTrait
|
||||
|
||||
protected function getInitiateParams()
|
||||
{
|
||||
$params = [];
|
||||
$config = $this->getConfig();
|
||||
$params = isset($config['params']) ? $config['params'] : [];
|
||||
|
||||
if (isset($this->getConfig()['acl'])) {
|
||||
$params['ACL'] = $this->getConfig()['acl'];
|
||||
if (isset($config['acl'])) {
|
||||
$params['ACL'] = $config['acl'];
|
||||
}
|
||||
|
||||
// Set the content type
|
||||
if ($type = $this->getSourceMimeType()) {
|
||||
// Set the ContentType if not already present
|
||||
if (empty($params['ContentType']) && $type = $this->getSourceMimeType()) {
|
||||
$params['ContentType'] = $type;
|
||||
}
|
||||
|
||||
|
||||
16
vendor/aws/aws-sdk-php/src/S3/ObjectCopier.php
vendored
16
vendor/aws/aws-sdk-php/src/S3/ObjectCopier.php
vendored
@@ -22,6 +22,7 @@ class ObjectCopier implements PromisorInterface
|
||||
private $options;
|
||||
|
||||
private static $defaults = [
|
||||
'before_lookup' => null,
|
||||
'before_upload' => null,
|
||||
'concurrency' => 5,
|
||||
'mup_threshold' => self::DEFAULT_MULTIPART_THRESHOLD,
|
||||
@@ -45,7 +46,9 @@ class ObjectCopier implements PromisorInterface
|
||||
* @param string $acl ACL to apply to the copy
|
||||
* (default: private).
|
||||
* @param array $options Options used to configure the
|
||||
* copy process.
|
||||
* copy process. Options passed in
|
||||
* through 'params' are added to
|
||||
* the sub commands.
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
@@ -70,14 +73,19 @@ class ObjectCopier implements PromisorInterface
|
||||
* Perform the configured copy asynchronously. Returns a promise that is
|
||||
* fulfilled with the result of the CompleteMultipartUpload or CopyObject
|
||||
* operation or rejected with an exception.
|
||||
*
|
||||
* @return \GuzzleHttp\Promise\Promise
|
||||
*/
|
||||
public function promise()
|
||||
{
|
||||
return \GuzzleHttp\Promise\coroutine(function () {
|
||||
$headObjectCommand = $this->client->getCommand(
|
||||
'HeadObject',
|
||||
$this->options['params'] + $this->source
|
||||
);
|
||||
if (is_callable($this->options['before_lookup'])) {
|
||||
$this->options['before_lookup']($headObjectCommand);
|
||||
}
|
||||
$objectStats = (yield $this->client->executeAsync(
|
||||
$this->client->getCommand('HeadObject', $this->source)
|
||||
$headObjectCommand
|
||||
));
|
||||
|
||||
if ($objectStats['ContentLength'] > $this->options['mup_threshold']) {
|
||||
|
||||
38
vendor/aws/aws-sdk-php/src/S3/ObjectUploader.php
vendored
38
vendor/aws/aws-sdk-php/src/S3/ObjectUploader.php
vendored
@@ -39,7 +39,9 @@ class ObjectUploader implements PromisorInterface
|
||||
* @param string $acl ACL to apply to the copy
|
||||
* (default: private).
|
||||
* @param array $options Options used to configure the
|
||||
* copy process.
|
||||
* copy process. Options passed in
|
||||
* through 'params' are added to
|
||||
* the sub command(s).
|
||||
*/
|
||||
public function __construct(
|
||||
S3ClientInterface $client,
|
||||
@@ -54,10 +56,7 @@ class ObjectUploader implements PromisorInterface
|
||||
$this->key = $key;
|
||||
$this->body = Psr7\stream_for($body);
|
||||
$this->acl = $acl;
|
||||
$this->options = array_intersect_key(
|
||||
$options + self::$defaults,
|
||||
self::$defaults
|
||||
);
|
||||
$this->options = $options + self::$defaults;
|
||||
}
|
||||
|
||||
public function promise()
|
||||
@@ -66,29 +65,24 @@ class ObjectUploader implements PromisorInterface
|
||||
$mup_threshold = $this->options['mup_threshold'];
|
||||
if ($this->requiresMultipart($this->body, $mup_threshold)) {
|
||||
// Perform a multipart upload.
|
||||
$this->options['before_initiate'] = function ($command) {
|
||||
foreach ($this->options['params'] as $k => $v) {
|
||||
$command[$k] = $v;
|
||||
}
|
||||
};
|
||||
return (new MultipartUploader($this->client, $this->body, [
|
||||
'bucket' => $this->bucket,
|
||||
'key' => $this->key,
|
||||
'acl' => $this->acl
|
||||
] + $this->options))->promise();
|
||||
} else {
|
||||
// Perform a regular PutObject operation.
|
||||
$command = $this->client->getCommand('PutObject', [
|
||||
'Bucket' => $this->bucket,
|
||||
'Key' => $this->key,
|
||||
'Body' => $this->body,
|
||||
'ACL' => $this->acl,
|
||||
] + $this->options['params']);
|
||||
if (is_callable($this->options['before_upload'])) {
|
||||
$this->options['before_upload']($command);
|
||||
}
|
||||
return $this->client->executeAsync($command);
|
||||
}
|
||||
|
||||
// Perform a regular PutObject operation.
|
||||
$command = $this->client->getCommand('PutObject', [
|
||||
'Bucket' => $this->bucket,
|
||||
'Key' => $this->key,
|
||||
'Body' => $this->body,
|
||||
'ACL' => $this->acl,
|
||||
] + $this->options['params']);
|
||||
if (is_callable($this->options['before_upload'])) {
|
||||
$this->options['before_upload']($command);
|
||||
}
|
||||
return $this->client->executeAsync($command);
|
||||
}
|
||||
|
||||
public function upload()
|
||||
|
||||
7
vendor/aws/aws-sdk-php/src/S3/PostObject.php
vendored
7
vendor/aws/aws-sdk-php/src/S3/PostObject.php
vendored
@@ -128,11 +128,12 @@ class PostObject
|
||||
{
|
||||
$uri = new Uri($this->client->getEndpoint());
|
||||
|
||||
if ($uri->getScheme() === 'https'
|
||||
&& strpos($this->bucket, '.') !== false
|
||||
if ($this->client->getConfig('use_path_style_endpoint') === true
|
||||
|| ($uri->getScheme() === 'https'
|
||||
&& strpos($this->bucket, '.') !== false)
|
||||
) {
|
||||
// Use path-style URLs
|
||||
$uri = $uri->withPath($this->bucket);
|
||||
$uri = $uri->withPath("/{$this->bucket}");
|
||||
} else {
|
||||
// Use virtual-style URLs
|
||||
$uri = $uri->withHost($this->bucket . '.' . $uri->getHost());
|
||||
|
||||
19
vendor/aws/aws-sdk-php/src/S3/PostObjectV4.php
vendored
19
vendor/aws/aws-sdk-php/src/S3/PostObjectV4.php
vendored
@@ -21,7 +21,6 @@ class PostObjectV4
|
||||
private $bucket;
|
||||
private $formAttributes;
|
||||
private $formInputs;
|
||||
private $jsonPolicy;
|
||||
|
||||
/**
|
||||
* Constructs the PostObject.
|
||||
@@ -35,7 +34,7 @@ class PostObjectV4
|
||||
* fields.
|
||||
* @param array $options Policy condition options
|
||||
* @param mixed $expiration Upload expiration time value. By
|
||||
* default: 1 hour vaild peroid.
|
||||
* default: 1 hour valid period.
|
||||
*/
|
||||
public function __construct(
|
||||
S3ClientInterface $client,
|
||||
@@ -55,9 +54,8 @@ class PostObjectV4
|
||||
];
|
||||
|
||||
$credentials = $this->client->getCredentials()->wait();
|
||||
$securityToken = $credentials->getSecurityToken();
|
||||
|
||||
if (null !== $securityToken) {
|
||||
if ($securityToken = $credentials->getSecurityToken()) {
|
||||
array_push($options, ['x-amz-security-token' => $securityToken]);
|
||||
$formInputs['X-Amz-Security-Token'] = $securityToken;
|
||||
}
|
||||
@@ -145,14 +143,17 @@ class PostObjectV4
|
||||
{
|
||||
$uri = new Uri($this->client->getEndpoint());
|
||||
|
||||
if ($uri->getScheme() === 'https'
|
||||
&& strpos($this->bucket, '.') !== false
|
||||
if ($this->client->getConfig('use_path_style_endpoint') === true
|
||||
|| ($uri->getScheme() === 'https'
|
||||
&& strpos($this->bucket, '.') !== false)
|
||||
) {
|
||||
// Use path-style URLs
|
||||
$uri = $uri->withPath($this->bucket);
|
||||
$uri = $uri->withPath("/{$this->bucket}");
|
||||
} else {
|
||||
// Use virtual-style URLs
|
||||
$uri = $uri->withHost($this->bucket . '.' . $uri->getHost());
|
||||
// Use virtual-style URLs if haven't been set up already
|
||||
if (strpos($uri->getHost(), $this->bucket . '.') !== 0) {
|
||||
$uri = $uri->withHost($this->bucket . '.' . $uri->getHost());
|
||||
}
|
||||
}
|
||||
|
||||
return (string) $uri;
|
||||
|
||||
96
vendor/aws/aws-sdk-php/src/S3/S3Client.php
vendored
96
vendor/aws/aws-sdk-php/src/S3/S3Client.php
vendored
@@ -14,8 +14,6 @@ use Aws\RetryMiddleware;
|
||||
use Aws\ResultInterface;
|
||||
use Aws\CommandInterface;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Promise;
|
||||
use GuzzleHttp\Psr7;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
/**
|
||||
@@ -33,10 +31,18 @@ use Psr\Http\Message\RequestInterface;
|
||||
* @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 = [])
|
||||
@@ -47,14 +53,22 @@ use Psr\Http\Message\RequestInterface;
|
||||
* @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 = [])
|
||||
@@ -63,6 +77,8 @@ use Psr\Http\Message\RequestInterface;
|
||||
* @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 = [])
|
||||
@@ -83,12 +99,20 @@ use Psr\Http\Message\RequestInterface;
|
||||
* @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 = [])
|
||||
@@ -105,14 +129,22 @@ use Psr\Http\Message\RequestInterface;
|
||||
* @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 = [])
|
||||
@@ -133,6 +165,8 @@ use Psr\Http\Message\RequestInterface;
|
||||
* @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 = [])
|
||||
@@ -179,6 +213,15 @@ class S3Client extends AwsClient implements S3ClientInterface
|
||||
. ' \'@use_dual_stack_endpoint\' to true or false.',
|
||||
'default' => false,
|
||||
],
|
||||
'use_path_style_endpoint' => [
|
||||
'type' => 'config',
|
||||
'valid' => ['bool'],
|
||||
'doc' => 'Set to true to send requests to an S3 path style'
|
||||
. ' endpoint by default.'
|
||||
. ' Can be enabled or disabled on individual operations by setting'
|
||||
. ' \'@use_path_style_endpoint\' to true or false.',
|
||||
'default' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -205,6 +248,11 @@ class S3Client extends AwsClient implements S3ClientInterface
|
||||
* 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_path_style_endpoint: (bool) Set to true to send requests to an S3
|
||||
* path style endpoint by default.
|
||||
* Can be enabled or disabled on individual operations by setting
|
||||
* '@use_path_style_endpoint\' to true or false. Note:
|
||||
* you cannot use it together with an accelerate endpoint.
|
||||
*
|
||||
* @param array $args
|
||||
*/
|
||||
@@ -219,20 +267,22 @@ class S3Client extends AwsClient implements S3ClientInterface
|
||||
's3.content_type'
|
||||
);
|
||||
|
||||
$stack->appendBuild(
|
||||
S3EndpointMiddleware::wrap(
|
||||
$this->getRegion(),
|
||||
[
|
||||
'dual_stack' => $this->getConfig('use_dual_stack_endpoint'),
|
||||
'accelerate' => $this->getConfig('use_accelerate_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');
|
||||
} else {
|
||||
$stack->appendBuild(
|
||||
S3EndpointMiddleware::wrap(
|
||||
$this->getRegion(),
|
||||
[
|
||||
'dual_stack' => $this->getConfig('use_dual_stack_endpoint'),
|
||||
'accelerate' => $this->getConfig('use_accelerate_endpoint'),
|
||||
'path_style' => $this->getConfig('use_path_style_endpoint')
|
||||
]
|
||||
),
|
||||
's3.endpoint_middleware'
|
||||
);
|
||||
}
|
||||
|
||||
$stack->appendSign(PutObjectUrlMiddleware::wrap(), 's3.put_object_url');
|
||||
@@ -416,9 +466,9 @@ class S3Client extends AwsClient implements S3ClientInterface
|
||||
}
|
||||
foreach ($nested as $steps) {
|
||||
if (isset($result[$steps[0]])) {
|
||||
foreach ($result[$steps[0]] as &$part) {
|
||||
foreach ($result[$steps[0]] as $key => $part) {
|
||||
if (isset($part[$steps[1]])) {
|
||||
$part[$steps[1]]
|
||||
$result[$steps[0]][$key][$steps[1]]
|
||||
= urldecode($part[$steps[1]]);
|
||||
}
|
||||
}
|
||||
@@ -448,24 +498,28 @@ class S3Client extends AwsClient implements S3ClientInterface
|
||||
|
||||
if ($decider($retries, $command, $request, $result, $error)) {
|
||||
return true;
|
||||
} elseif ($error instanceof AwsException
|
||||
}
|
||||
|
||||
if ($error instanceof AwsException
|
||||
&& $retries < $maxRetries
|
||||
) {
|
||||
if (
|
||||
$error->getResponse()
|
||||
if ($error->getResponse()
|
||||
&& $error->getResponse()->getStatusCode() >= 400
|
||||
) {
|
||||
return strpos(
|
||||
$error->getResponse()->getBody(),
|
||||
'Your socket connection to the server'
|
||||
) !== false;
|
||||
} elseif ($error->getPrevious() instanceof RequestException) {
|
||||
$error->getResponse()->getBody(),
|
||||
'Your socket connection to the server'
|
||||
) !== false;
|
||||
}
|
||||
|
||||
if ($error->getPrevious() instanceof RequestException) {
|
||||
// All commands except CompleteMultipartUpload are
|
||||
// idempotent and may be retried without worry if a
|
||||
// networking error has occurred.
|
||||
return $command->getName() !== 'CompleteMultipartUpload';
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
87
vendor/aws/aws-sdk-php/src/S3/S3ClientTrait.php
vendored
87
vendor/aws/aws-sdk-php/src/S3/S3ClientTrait.php
vendored
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Aws\S3;
|
||||
|
||||
use Aws\Api\Parser\PayloadParserTrait;
|
||||
use Aws\CommandInterface;
|
||||
use Aws\Exception\AwsException;
|
||||
use Aws\HandlerList;
|
||||
@@ -15,6 +16,11 @@ use GuzzleHttp\Promise\RejectedPromise;
|
||||
*/
|
||||
trait S3ClientTrait
|
||||
{
|
||||
use PayloadParserTrait;
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::upload()
|
||||
*/
|
||||
public function upload(
|
||||
$bucket,
|
||||
$key,
|
||||
@@ -27,6 +33,9 @@ trait S3ClientTrait
|
||||
->wait();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::uploadAsync()
|
||||
*/
|
||||
public function uploadAsync(
|
||||
$bucket,
|
||||
$key,
|
||||
@@ -38,6 +47,9 @@ trait S3ClientTrait
|
||||
->promise();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::copy()
|
||||
*/
|
||||
public function copy(
|
||||
$fromB,
|
||||
$fromK,
|
||||
@@ -50,6 +62,9 @@ trait S3ClientTrait
|
||||
->wait();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::copyAsync()
|
||||
*/
|
||||
public function copyAsync(
|
||||
$fromB,
|
||||
$fromK,
|
||||
@@ -74,11 +89,17 @@ trait S3ClientTrait
|
||||
->promise();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::registerStreamWrapper()
|
||||
*/
|
||||
public function registerStreamWrapper()
|
||||
{
|
||||
StreamWrapper::register($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::deleteMatchingObjects()
|
||||
*/
|
||||
public function deleteMatchingObjects(
|
||||
$bucket,
|
||||
$prefix = '',
|
||||
@@ -89,6 +110,9 @@ trait S3ClientTrait
|
||||
->wait();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::deleteMatchingObjectsAsync()
|
||||
*/
|
||||
public function deleteMatchingObjectsAsync(
|
||||
$bucket,
|
||||
$prefix = '',
|
||||
@@ -114,6 +138,9 @@ trait S3ClientTrait
|
||||
->promise();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::uploadDirectory()
|
||||
*/
|
||||
public function uploadDirectory(
|
||||
$directory,
|
||||
$bucket,
|
||||
@@ -124,6 +151,9 @@ trait S3ClientTrait
|
||||
->wait();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::uploadDirectoryAsync()
|
||||
*/
|
||||
public function uploadDirectoryAsync(
|
||||
$directory,
|
||||
$bucket,
|
||||
@@ -134,6 +164,9 @@ trait S3ClientTrait
|
||||
return (new Transfer($this, $directory, $d, $options))->promise();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::downloadBucket()
|
||||
*/
|
||||
public function downloadBucket(
|
||||
$directory,
|
||||
$bucket,
|
||||
@@ -144,6 +177,9 @@ trait S3ClientTrait
|
||||
->wait();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::downloadBucketAsync()
|
||||
*/
|
||||
public function downloadBucketAsync(
|
||||
$directory,
|
||||
$bucket,
|
||||
@@ -154,12 +190,17 @@ trait S3ClientTrait
|
||||
return (new Transfer($this, $s, $directory, $options))->promise();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::determineBucketRegion()
|
||||
*/
|
||||
public function determineBucketRegion($bucketName)
|
||||
{
|
||||
return $this->determineBucketRegionAsync($bucketName)->wait();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::determineBucketRegionAsync()
|
||||
*
|
||||
* @param string $bucketName
|
||||
*
|
||||
* @return PromiseInterface
|
||||
@@ -175,15 +216,42 @@ 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();
|
||||
}, function (AwsException $e) {
|
||||
$response = $e->getResponse();
|
||||
if ($response === null) {
|
||||
throw $exception;
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if ($e->getAwsErrorCode() === 'AuthorizationHeaderMalformed') {
|
||||
$region = $this->determineBucketRegionFromExceptionBody(
|
||||
$response->getBody()
|
||||
);
|
||||
if (!empty($region)) {
|
||||
return $region;
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $response->getHeaderLine('x-amz-bucket-region');
|
||||
});
|
||||
}
|
||||
|
||||
private function determineBucketRegionFromExceptionBody($responseBody)
|
||||
{
|
||||
try {
|
||||
$element = $this->parseXml($responseBody);
|
||||
if (!empty($element->Region)) {
|
||||
return (string)$element->Region;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Fallthrough on exceptions from parsing
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::doesBucketExist()
|
||||
*/
|
||||
public function doesBucketExist($bucket)
|
||||
{
|
||||
return $this->checkExistenceWithCommand(
|
||||
@@ -191,6 +259,9 @@ trait S3ClientTrait
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::doesObjectExist()
|
||||
*/
|
||||
public function doesObjectExist($bucket, $key, array $options = [])
|
||||
{
|
||||
return $this->checkExistenceWithCommand(
|
||||
@@ -225,16 +296,26 @@ trait S3ClientTrait
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::execute()
|
||||
*/
|
||||
abstract public function execute(CommandInterface $command);
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::getCommand()
|
||||
*/
|
||||
abstract public function getCommand($name, array $args = []);
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::getHandlerList()
|
||||
*
|
||||
* @return HandlerList
|
||||
*/
|
||||
abstract public function getHandlerList();
|
||||
|
||||
/**
|
||||
* @see S3ClientInterface::getIterator()
|
||||
*
|
||||
* @return \Iterator
|
||||
*/
|
||||
abstract public function getIterator($name, array $args = []);
|
||||
|
||||
@@ -6,7 +6,9 @@ use Psr\Http\Message\RequestInterface;
|
||||
|
||||
/**
|
||||
* Used to update the URL used for S3 requests to support:
|
||||
* S3 Accelerate, S3 DualStack or Both
|
||||
* S3 Accelerate, S3 DualStack or Both. It will build to
|
||||
* host style paths unless specified, including for S3
|
||||
* DualStack.
|
||||
*
|
||||
* IMPORTANT: this middleware must be added after the "build" step.
|
||||
*
|
||||
@@ -24,11 +26,15 @@ class S3EndpointMiddleware
|
||||
const DUALSTACK = 1;
|
||||
const ACCELERATE = 2;
|
||||
const ACCELERATE_DUALSTACK = 3;
|
||||
const PATH_STYLE = 4;
|
||||
const HOST_STYLE = 5;
|
||||
|
||||
/** @var bool */
|
||||
private $accelerateByDefault;
|
||||
/** @var bool */
|
||||
private $dualStackByDefault;
|
||||
/** @var bool */
|
||||
private $pathStyleByDefault;
|
||||
/** @var string */
|
||||
private $region;
|
||||
/** @var callable */
|
||||
@@ -54,6 +60,8 @@ class S3EndpointMiddleware
|
||||
$region,
|
||||
array $options
|
||||
) {
|
||||
$this->pathStyleByDefault = isset($options['path_style'])
|
||||
? (bool) $options['path_style'] : false;
|
||||
$this->dualStackByDefault = isset($options['dual_stack'])
|
||||
? (bool) $options['dual_stack'] : false;
|
||||
$this->accelerateByDefault = isset($options['accelerate'])
|
||||
@@ -64,12 +72,15 @@ class S3EndpointMiddleware
|
||||
|
||||
public function __invoke(CommandInterface $command, RequestInterface $request)
|
||||
{
|
||||
$endpointPattern = $this->endpointPatternDecider($command);
|
||||
switch ($endpointPattern) {
|
||||
switch ($this->endpointPatternDecider($command, $request)) {
|
||||
case self::HOST_STYLE:
|
||||
$request = $this->applyHostStyleEndpoint($command, $request);
|
||||
break;
|
||||
case self::NO_PATTERN:
|
||||
case self::PATH_STYLE:
|
||||
break;
|
||||
case self::DUALSTACK:
|
||||
$request = $this->applyDualStackEndpoint($request);
|
||||
$request = $this->applyDualStackEndpoint($command, $request);
|
||||
break;
|
||||
case self::ACCELERATE:
|
||||
$request = $this->applyAccelerateEndpoint(
|
||||
@@ -91,12 +102,27 @@ class S3EndpointMiddleware
|
||||
return $nextHandler($command, $request);
|
||||
}
|
||||
|
||||
private function endpointPatternDecider(CommandInterface $command)
|
||||
{
|
||||
private static function isRequestHostStyleCompatible(
|
||||
CommandInterface $command,
|
||||
RequestInterface $request
|
||||
) {
|
||||
return S3Client::isBucketDnsCompatible($command['Bucket'])
|
||||
&& (
|
||||
$request->getUri()->getScheme() === 'http'
|
||||
|| strpos($command['Bucket'], '.') === false
|
||||
);
|
||||
}
|
||||
|
||||
private function endpointPatternDecider(
|
||||
CommandInterface $command,
|
||||
RequestInterface $request
|
||||
) {
|
||||
$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;
|
||||
$pathStyle = isset($command['@use_path_style_endpoint'])
|
||||
? $command['@use_path_style_endpoint'] : $this->pathStyleByDefault;
|
||||
|
||||
if ($accelerate && $dualStack) {
|
||||
// When try to enable both for operations excluded from s3-accelerate,
|
||||
@@ -104,12 +130,23 @@ class S3EndpointMiddleware
|
||||
return $this->canAccelerate($command)
|
||||
? self::ACCELERATE_DUALSTACK
|
||||
: self::DUALSTACK;
|
||||
} elseif ($accelerate && $this->canAccelerate($command)) {
|
||||
}
|
||||
|
||||
if ($accelerate && $this->canAccelerate($command)) {
|
||||
return self::ACCELERATE;
|
||||
} elseif ($dualStack) {
|
||||
}
|
||||
|
||||
if ($dualStack) {
|
||||
return self::DUALSTACK;
|
||||
}
|
||||
return self::NO_PATTERN;
|
||||
|
||||
if (!$pathStyle
|
||||
&& self::isRequestHostStyleCompatible($command, $request)
|
||||
) {
|
||||
return self::HOST_STYLE;
|
||||
}
|
||||
|
||||
return self::PATH_STYLE;
|
||||
}
|
||||
|
||||
private function canAccelerate(CommandInterface $command)
|
||||
@@ -118,12 +155,48 @@ class S3EndpointMiddleware
|
||||
&& S3Client::isBucketDnsCompatible($command['Bucket']);
|
||||
}
|
||||
|
||||
private function applyDualStackEndpoint(RequestInterface $request)
|
||||
private function getBucketStyleHost(CommandInterface $command, $host)
|
||||
{
|
||||
// For operations on the base host (e.g. ListBuckets)
|
||||
if (!isset($command['Bucket'])) {
|
||||
return $host;
|
||||
}
|
||||
|
||||
return "{$command['Bucket']}.{$host}";
|
||||
}
|
||||
|
||||
private function applyHostStyleEndpoint(
|
||||
CommandInterface $command,
|
||||
RequestInterface $request
|
||||
) {
|
||||
$uri = $request->getUri();
|
||||
$request = $request->withUri(
|
||||
$uri->withHost($this->getBucketStyleHost(
|
||||
$command,
|
||||
$uri->getHost()
|
||||
))
|
||||
->withPath($this->getBucketlessPath(
|
||||
$uri->getPath(),
|
||||
$command
|
||||
))
|
||||
);
|
||||
return $request;
|
||||
}
|
||||
|
||||
private function applyDualStackEndpoint(
|
||||
CommandInterface $command,
|
||||
RequestInterface $request
|
||||
) {
|
||||
$request = $request->withUri(
|
||||
$request->getUri()
|
||||
->withHost($this->getDualStackHost())
|
||||
);
|
||||
if (empty($command['@use_path_style_endpoint'])
|
||||
&& !$this->pathStyleByDefault
|
||||
&& self::isRequestHostStyleCompatible($command, $request)
|
||||
) {
|
||||
$request = $this->applyHostStyleEndpoint($command, $request);
|
||||
}
|
||||
return $request;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
27
vendor/aws/aws-sdk-php/src/S3/S3UriParser.php
vendored
27
vendor/aws/aws-sdk-php/src/S3/S3UriParser.php
vendored
@@ -10,6 +10,7 @@ use Psr\Http\Message\UriInterface;
|
||||
class S3UriParser
|
||||
{
|
||||
private $pattern = '/^(.+\\.)?s3[.-]([A-Za-z0-9-]+)\\./';
|
||||
private $streamWrapperScheme = 's3';
|
||||
|
||||
private static $defaultResult = [
|
||||
'path_style' => true,
|
||||
@@ -19,7 +20,8 @@ class S3UriParser
|
||||
];
|
||||
|
||||
/**
|
||||
* Parses a URL into an associative array of Amazon S3 data including:
|
||||
* Parses a URL or S3 StreamWrapper Uri (s3://) into an associative array
|
||||
* of Amazon S3 data including:
|
||||
*
|
||||
* - bucket: The Amazon S3 bucket (null if none)
|
||||
* - key: The Amazon S3 key (null if none)
|
||||
@@ -34,6 +36,11 @@ class S3UriParser
|
||||
public function parse($uri)
|
||||
{
|
||||
$url = Psr7\uri_for($uri);
|
||||
|
||||
if ($url->getScheme() == $this->streamWrapperScheme) {
|
||||
return $this->parseStreamWrapper($url);
|
||||
}
|
||||
|
||||
if (!$url->getHost()) {
|
||||
throw new \InvalidArgumentException('No hostname found in URI: '
|
||||
. $uri);
|
||||
@@ -54,9 +61,25 @@ class S3UriParser
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function parseStreamWrapper(UriInterface $url)
|
||||
{
|
||||
$result = self::$defaultResult;
|
||||
$result['path_style'] = false;
|
||||
|
||||
$result['bucket'] = $url->getHost();
|
||||
if ($url->getPath()) {
|
||||
$key = ltrim($url->getPath(), '/ ');
|
||||
if (!empty($key)) {
|
||||
$result['key'] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function parseCustomEndpoint(UriInterface $url)
|
||||
{
|
||||
$result = $result = self::$defaultResult;
|
||||
$result = self::$defaultResult;
|
||||
$path = ltrim($url->getPath(), '/ ');
|
||||
$segments = explode('/', $path, 2);
|
||||
|
||||
|
||||
@@ -281,10 +281,10 @@ class StreamWrapper
|
||||
// Return as if it is a bucket to account for console
|
||||
// bucket objects (e.g., zero-byte object "foo/")
|
||||
return $this->formatUrlStat($path);
|
||||
} else {
|
||||
// Attempt to stat and cache regular object
|
||||
return $this->formatUrlStat($result->toArray());
|
||||
}
|
||||
|
||||
// Attempt to stat and cache regular object
|
||||
return $this->formatUrlStat($result->toArray());
|
||||
} catch (S3Exception $e) {
|
||||
// Maybe this isn't an actual key, but a prefix. Do a prefix
|
||||
// listing of objects to determine.
|
||||
|
||||
61
vendor/aws/aws-sdk-php/src/S3/Transfer.php
vendored
61
vendor/aws/aws-sdk-php/src/S3/Transfer.php
vendored
@@ -3,8 +3,8 @@ namespace Aws\S3;
|
||||
|
||||
use Aws;
|
||||
use Aws\CommandInterface;
|
||||
use Aws\Exception\AwsException;
|
||||
use GuzzleHttp\Promise;
|
||||
use GuzzleHttp\Psr7;
|
||||
use GuzzleHttp\Promise\PromisorInterface;
|
||||
use Iterator;
|
||||
|
||||
@@ -46,10 +46,9 @@ class Transfer implements PromisorInterface
|
||||
* iterator. If the $source option is not an array, then this option is
|
||||
* ignored.
|
||||
* - before: (callable) A callback to invoke before each transfer. The
|
||||
* callback accepts the following positional arguments: string $source,
|
||||
* string $dest, Aws\CommandInterface $command. The provided command will
|
||||
* be either a GetObject, PutObject, InitiateMultipartUpload, or
|
||||
* UploadPart command.
|
||||
* callback accepts a single argument: Aws\CommandInterface $command.
|
||||
* The provided command will be either a GetObject, PutObject,
|
||||
* InitiateMultipartUpload, or UploadPart command.
|
||||
* - mup_threshold: (int) Size in bytes in which a multipart upload should
|
||||
* be used instead of PutObject. Defaults to 20971520 (20 MB).
|
||||
* - concurrency: (int, default=5) Number of files to upload concurrently.
|
||||
@@ -213,6 +212,25 @@ class Transfer implements PromisorInterface
|
||||
return rtrim(str_replace('\\', '/', $path), '/');
|
||||
}
|
||||
|
||||
private function resolveUri($uri)
|
||||
{
|
||||
$resolved = [];
|
||||
$sections = explode('/', $uri);
|
||||
foreach ($sections as $section) {
|
||||
if ($section === '.' || $section === '') {
|
||||
continue;
|
||||
}
|
||||
if ($section === '..') {
|
||||
array_pop($resolved);
|
||||
} else {
|
||||
$resolved []= $section;
|
||||
}
|
||||
}
|
||||
|
||||
return ($uri[0] === '/' ? '/' : '')
|
||||
. implode('/', $resolved);
|
||||
}
|
||||
|
||||
private function createDownloadPromise()
|
||||
{
|
||||
$parts = $this->getS3Args($this->sourceMetadata['path']);
|
||||
@@ -223,8 +241,30 @@ class Transfer implements PromisorInterface
|
||||
$commands = [];
|
||||
foreach ($this->getDownloadsIterator() as $object) {
|
||||
// Prepare the sink.
|
||||
$sink = $this->destination['path'] . '/'
|
||||
. preg_replace('/^' . preg_quote($prefix, '/') . '/', '', $object);
|
||||
$objectKey = preg_replace('/^' . preg_quote($prefix, '/') . '/', '', $object);
|
||||
|
||||
$resolveSink = $this->destination['path'] . '/';
|
||||
if (isset($parts['Key']) && strpos($objectKey, $parts['Key']) !== 0) {
|
||||
$resolveSink .= $parts['Key'] . '/';
|
||||
}
|
||||
$resolveSink .= $objectKey;
|
||||
$sink = $this->destination['path'] . '/' . $objectKey;
|
||||
|
||||
$command = $this->client->getCommand(
|
||||
'GetObject',
|
||||
$this->getS3Args($object) + ['@http' => ['sink' => $sink]]
|
||||
);
|
||||
|
||||
if (strpos(
|
||||
$this->resolveUri($resolveSink),
|
||||
$this->destination['path']
|
||||
) !== 0
|
||||
) {
|
||||
throw new AwsException(
|
||||
'Cannot download key ' . $objectKey
|
||||
. ', its relative path resolves outside the'
|
||||
. ' parent directory', $command);
|
||||
}
|
||||
|
||||
// Create the directory if needed.
|
||||
$dir = dirname($sink);
|
||||
@@ -233,10 +273,7 @@ class Transfer implements PromisorInterface
|
||||
}
|
||||
|
||||
// Create the command.
|
||||
$commands []= $this->client->getCommand(
|
||||
'GetObject',
|
||||
$this->getS3Args($object) + ['@http' => ['sink' => $sink]]
|
||||
);
|
||||
$commands []= $command;
|
||||
}
|
||||
|
||||
// Create a GetObject command pool and return the promise.
|
||||
@@ -333,7 +370,7 @@ class Transfer implements PromisorInterface
|
||||
preg_replace('#^' . preg_quote($this->sourceMetadata['path']) . '#', '', $filename),
|
||||
'/\\'
|
||||
);
|
||||
|
||||
|
||||
if (isset($this->s3Args['Key'])) {
|
||||
return rtrim($this->s3Args['Key'], '/').'/'.$relative_file_path;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user