v2: Updates

* Simplifies & beautifies everything
* Introduces a new Class system.
* Errors are defaulted to AWS's handler.
* New function names & more efficient handling.
* Should fix a majority of the errors.

Please read the README for more!
This commit is contained in:
Devang Srivastava 2020-09-28 15:32:51 +05:30
parent ad0726e41e
commit e6d7753dc8
1095 changed files with 45088 additions and 2911 deletions

View file

@ -0,0 +1,9 @@
<?php
namespace Aws\S3Control\Exception;
use Aws\Exception\AwsException;
/**
* Represents an error interacting with the **AWS S3 Control** service.
*/
class S3ControlException extends AwsException {}

View file

@ -0,0 +1,94 @@
<?php
namespace Aws\S3Control;
use Aws\AwsClient;
/**
* This client is used to interact with the **AWS S3 Control** service.
* @method \Aws\Result createAccessPoint(array $args = [])
* @method \GuzzleHttp\Promise\Promise createAccessPointAsync(array $args = [])
* @method \Aws\Result createJob(array $args = [])
* @method \GuzzleHttp\Promise\Promise createJobAsync(array $args = [])
* @method \Aws\Result deleteAccessPoint(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteAccessPointAsync(array $args = [])
* @method \Aws\Result deleteAccessPointPolicy(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteAccessPointPolicyAsync(array $args = [])
* @method \Aws\Result deleteJobTagging(array $args = [])
* @method \GuzzleHttp\Promise\Promise deleteJobTaggingAsync(array $args = [])
* @method \Aws\Result deletePublicAccessBlock(array $args = [])
* @method \GuzzleHttp\Promise\Promise deletePublicAccessBlockAsync(array $args = [])
* @method \Aws\Result describeJob(array $args = [])
* @method \GuzzleHttp\Promise\Promise describeJobAsync(array $args = [])
* @method \Aws\Result getAccessPoint(array $args = [])
* @method \GuzzleHttp\Promise\Promise getAccessPointAsync(array $args = [])
* @method \Aws\Result getAccessPointPolicy(array $args = [])
* @method \GuzzleHttp\Promise\Promise getAccessPointPolicyAsync(array $args = [])
* @method \Aws\Result getAccessPointPolicyStatus(array $args = [])
* @method \GuzzleHttp\Promise\Promise getAccessPointPolicyStatusAsync(array $args = [])
* @method \Aws\Result getJobTagging(array $args = [])
* @method \GuzzleHttp\Promise\Promise getJobTaggingAsync(array $args = [])
* @method \Aws\Result getPublicAccessBlock(array $args = [])
* @method \GuzzleHttp\Promise\Promise getPublicAccessBlockAsync(array $args = [])
* @method \Aws\Result listAccessPoints(array $args = [])
* @method \GuzzleHttp\Promise\Promise listAccessPointsAsync(array $args = [])
* @method \Aws\Result listJobs(array $args = [])
* @method \GuzzleHttp\Promise\Promise listJobsAsync(array $args = [])
* @method \Aws\Result putAccessPointPolicy(array $args = [])
* @method \GuzzleHttp\Promise\Promise putAccessPointPolicyAsync(array $args = [])
* @method \Aws\Result putJobTagging(array $args = [])
* @method \GuzzleHttp\Promise\Promise putJobTaggingAsync(array $args = [])
* @method \Aws\Result putPublicAccessBlock(array $args = [])
* @method \GuzzleHttp\Promise\Promise putPublicAccessBlockAsync(array $args = [])
* @method \Aws\Result updateJobPriority(array $args = [])
* @method \GuzzleHttp\Promise\Promise updateJobPriorityAsync(array $args = [])
* @method \Aws\Result updateJobStatus(array $args = [])
* @method \GuzzleHttp\Promise\Promise updateJobStatusAsync(array $args = [])
*/
class S3ControlClient extends AwsClient
{
public static function getArguments()
{
$args = parent::getArguments();
return $args + [
'use_dual_stack_endpoint' => [
'type' => 'config',
'valid' => ['bool'],
'doc' => 'Set to true to send requests to an S3 Control 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.',
'default' => false,
],
];
}
/**
* {@inheritdoc}
*
* In addition to the options available to
* {@see Aws\AwsClient::__construct}, S3ControlClient accepts the following
* option:
*
* - use_dual_stack_endpoint: (bool) Set to true to send requests to an S3
* Control 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.
*
* @param array $args
*/
public function __construct(array $args)
{
parent::__construct($args);
$stack = $this->getHandlerList();
$stack->appendBuild(
S3ControlEndpointMiddleware::wrap(
$this->getRegion(),
[
'dual_stack' => $this->getConfig('use_dual_stack_endpoint'),
]
),
's3control.endpoint_middleware'
);
}
}

View file

@ -0,0 +1,126 @@
<?php
namespace Aws\S3Control;
use Aws\CommandInterface;
use Psr\Http\Message\RequestInterface;
/**
* Used to update the URL used for S3 Control requests to support S3 Control
* DualStack. It will build to host style paths, including for S3 Control
* DualStack.
*
* IMPORTANT: this middleware must be added after the "build" step.
*
* @internal
*/
class S3ControlEndpointMiddleware
{
const NO_PATTERN = 0;
const DUALSTACK = 1;
/** @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->region = (string) $region;
$this->nextHandler = $nextHandler;
}
public function __invoke(CommandInterface $command, RequestInterface $request)
{
if ($this->isDualStackRequest($command, $request)) {
$request = $this->applyDualStackEndpoint($command, $request);
}
$request = $this->applyHostStyleEndpoint($command, $request)
->withoutHeader('x-amz-account-id');
unset($command['AccountId']);
$nextHandler = $this->nextHandler;
return $nextHandler($command, $request);
}
private function isDualStackRequest(
CommandInterface $command,
RequestInterface $request
) {
return isset($command['@use_dual_stack_endpoint'])
? $command['@use_dual_stack_endpoint'] : $this->dualStackByDefault;
}
private function getDualStackHost($host)
{
$parts = explode(".{$this->region}.", $host);
return $parts[0] . ".dualstack.{$this->region}." . $parts[1];
}
private function applyDualStackEndpoint(
CommandInterface $command,
RequestInterface $request
) {
$uri = $request->getUri();
return $request->withUri(
$uri->withHost($this->getDualStackHost(
$uri->getHost()
))
);
}
private function getAccountIdStyleHost(CommandInterface $command, $host)
{
if (!\Aws\is_valid_hostname($command['AccountId'])) {
throw new \InvalidArgumentException(
"The supplied parameters result in an invalid hostname: '{$command['AccountId']}.{$host}'."
);
}
return "{$command['AccountId']}.{$host}";
}
private function getAccountIdlessPath($path, CommandInterface $command)
{
$pattern = '/^\\/' . preg_quote($command['AccountId'], '/') . '/';
return preg_replace($pattern, '', $path) ?: '/';
}
private function applyHostStyleEndpoint(
CommandInterface $command,
RequestInterface $request
) {
$uri = $request->getUri();
$request = $request->withUri(
$uri->withHost($this->getAccountIdStyleHost(
$command,
$uri->getHost()
))
->withPath($this->getAccountIdlessPath(
$uri->getPath(),
$command
))
);
return $request;
}
}