installed plugin Infinite Uploads version 2.0.8

This commit is contained in:
2025-05-02 12:03:21 +00:00
committed by Gitium
parent 7ca941b591
commit 8fefb19ab4
1179 changed files with 99739 additions and 0 deletions

View File

@ -0,0 +1,89 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Endpoint;
use UglyRobot\Infinite_Uploads\Aws\Exception\UnresolvedEndpointException;
/**
* Endpoint providers.
*
* An endpoint provider is a function that accepts a hash of endpoint options,
* including but not limited to "service" and "region" key value pairs. The
* endpoint provider function returns a hash of endpoint data, which MUST
* include an "endpoint" key value pair that represents the resolved endpoint
* or NULL if an endpoint cannot be determined.
*
* You can wrap your calls to an endpoint provider with the
* {@see EndpointProvider::resolve} function to ensure that an endpoint hash is
* created. If an endpoint hash is not created, then the resolve() function
* will throw an {@see Aws\Exception\UnresolvedEndpointException}.
*
* use Aws\Endpoint\EndpointProvider;
* $provider = EndpointProvider::defaultProvider();
* // Returns an array or NULL.
* $endpoint = $provider(['service' => 'ec2', 'region' => 'us-west-2']);
* // Returns an endpoint array or throws.
* $endpoint = EndpointProvider::resolve($provider, [
* 'service' => 'ec2',
* 'region' => 'us-west-2'
* ]);
*
* You can compose multiple providers into a single provider using
* {@see Aws\or_chain}. This function accepts providers as arguments and
* returns a new function that will invoke each provider until a non-null value
* is returned.
*
* $a = function (array $args) {
* if ($args['region'] === 'my-test-region') {
* return ['endpoint' => 'http://localhost:123/api'];
* }
* };
* $b = EndpointProvider::defaultProvider();
* $c = \Aws\or_chain($a, $b);
* $config = ['service' => 'ec2', 'region' => 'my-test-region'];
* $res = $c($config); // $a handles this.
* $config['region'] = 'us-west-2';
* $res = $c($config); // $b handles this.
*/
class EndpointProvider
{
/**
* Resolves and endpoint provider and ensures a non-null return value.
*
* @param callable $provider Provider function to invoke.
* @param array $args Endpoint arguments to pass to the provider.
*
* @return array
* @throws UnresolvedEndpointException
*/
public static function resolve(callable $provider, array $args = [])
{
$result = $provider($args);
if (is_array($result)) {
return $result;
}
throw new \UglyRobot\Infinite_Uploads\Aws\Exception\UnresolvedEndpointException('Unable to resolve an endpoint using the provider arguments: ' . json_encode($args) . '. Note: you can provide an "endpoint" ' . 'option to a client constructor to bypass invoking an endpoint ' . 'provider.');
}
/**
* Creates and returns the default SDK endpoint provider.
*
* @deprecated Use an instance of \Aws\Endpoint\Partition instead.
*
* @return callable
*/
public static function defaultProvider()
{
return \UglyRobot\Infinite_Uploads\Aws\Endpoint\PartitionEndpointProvider::defaultProvider();
}
/**
* Creates and returns an endpoint provider that uses patterns from an
* array.
*
* @param array $patterns Endpoint patterns
*
* @return callable
*/
public static function patterns(array $patterns)
{
return new \UglyRobot\Infinite_Uploads\Aws\Endpoint\PatternEndpointProvider($patterns);
}
}

View File

@ -0,0 +1,151 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Endpoint;
use ArrayAccess;
use UglyRobot\Infinite_Uploads\Aws\HasDataTrait;
use UglyRobot\Infinite_Uploads\Aws\Sts\RegionalEndpoints\ConfigurationProvider;
use UglyRobot\Infinite_Uploads\Aws\S3\RegionalEndpoint\ConfigurationProvider as S3ConfigurationProvider;
use InvalidArgumentException as Iae;
/**
* Default implementation of an AWS partition.
*/
final class Partition implements \ArrayAccess, \UglyRobot\Infinite_Uploads\Aws\Endpoint\PartitionInterface
{
use HasDataTrait;
private $stsLegacyGlobalRegions = ['ap-northeast-1', 'ap-south-1', 'ap-southeast-1', 'ap-southeast-2', 'aws-global', 'ca-central-1', 'eu-central-1', 'eu-north-1', 'eu-west-1', 'eu-west-2', 'eu-west-3', 'sa-east-1', 'us-east-1', 'us-east-2', 'us-west-1', 'us-west-2'];
/**
* The partition constructor accepts the following options:
*
* - `partition`: (string, required) The partition name as specified in an
* ARN (e.g., `aws`)
* - `partitionName`: (string) The human readable name of the partition
* (e.g., "AWS Standard")
* - `dnsSuffix`: (string, required) The DNS suffix of the partition. This
* value is used to determine how endpoints in the partition are resolved.
* - `regionRegex`: (string) A PCRE regular expression that specifies the
* pattern that region names in the endpoint adhere to.
* - `regions`: (array, required) A map of the regions in the partition.
* Each key is the region as present in a hostname (e.g., `us-east-1`),
* and each value is a structure containing region information.
* - `defaults`: (array) A map of default key value pairs to apply to each
* endpoint of the partition. Any value in an `endpoint` definition will
* supersede any values specified in `defaults`.
* - `services`: (array, required) A map of service endpoint prefix name
* (the value found in a hostname) to information about the service.
*
* @param array $definition
*
* @throws Iae if any required options are missing
*/
public function __construct(array $definition)
{
foreach (['partition', 'regions', 'services', 'dnsSuffix'] as $key) {
if (!isset($definition[$key])) {
throw new \InvalidArgumentException("Partition missing required {$key} field");
}
}
$this->data = $definition;
}
public function getName()
{
return $this->data['partition'];
}
/**
* @internal
* @return mixed
*/
public function getDnsSuffix()
{
return $this->data['dnsSuffix'];
}
public function isRegionMatch($region, $service)
{
if (isset($this->data['regions'][$region]) || isset($this->data['services'][$service]['endpoints'][$region])) {
return true;
}
if (isset($this->data['regionRegex'])) {
return (bool) preg_match("@{$this->data['regionRegex']}@", $region);
}
return false;
}
public function getAvailableEndpoints($service, $allowNonRegionalEndpoints = false)
{
if ($this->isServicePartitionGlobal($service)) {
return [$this->getPartitionEndpoint($service)];
}
if (isset($this->data['services'][$service]['endpoints'])) {
$serviceRegions = array_keys($this->data['services'][$service]['endpoints']);
return $allowNonRegionalEndpoints ? $serviceRegions : array_intersect($serviceRegions, array_keys($this->data['regions']));
}
return [];
}
public function __invoke(array $args = [])
{
$service = isset($args['service']) ? $args['service'] : '';
$region = isset($args['region']) ? $args['region'] : '';
$scheme = isset($args['scheme']) ? $args['scheme'] : 'https';
$options = isset($args['options']) ? $args['options'] : [];
$data = $this->getEndpointData($service, $region, $options);
return ['endpoint' => "{$scheme}://" . $this->formatEndpoint(isset($data['hostname']) ? $data['hostname'] : '', $service, $region), 'signatureVersion' => $this->getSignatureVersion($data), 'signingRegion' => isset($data['credentialScope']['region']) ? $data['credentialScope']['region'] : $region, 'signingName' => isset($data['credentialScope']['service']) ? $data['credentialScope']['service'] : $service];
}
private function getEndpointData($service, $region, $options)
{
$resolved = $this->resolveRegion($service, $region, $options);
$data = isset($this->data['services'][$service]['endpoints'][$resolved]) ? $this->data['services'][$service]['endpoints'][$resolved] : [];
$data += isset($this->data['services'][$service]['defaults']) ? $this->data['services'][$service]['defaults'] : [];
$data += isset($this->data['defaults']) ? $this->data['defaults'] : [];
return $data;
}
private function getSignatureVersion(array $data)
{
static $supportedBySdk = ['s3v4', 'v4', 'anonymous'];
$possibilities = array_intersect($supportedBySdk, isset($data['signatureVersions']) ? $data['signatureVersions'] : ['v4']);
return array_shift($possibilities);
}
private function resolveRegion($service, $region, $options)
{
if ($this->isServicePartitionGlobal($service) || $this->isStsLegacyEndpointUsed($service, $region, $options) || $this->isS3LegacyEndpointUsed($service, $region, $options)) {
return $this->getPartitionEndpoint($service);
}
return $region;
}
private function isServicePartitionGlobal($service)
{
return isset($this->data['services'][$service]['isRegionalized']) && false === $this->data['services'][$service]['isRegionalized'] && isset($this->data['services'][$service]['partitionEndpoint']);
}
/**
* STS legacy endpoints used for valid regions unless option is explicitly
* set to 'regional'
*
* @param string $service
* @param string $region
* @param array $options
* @return bool
*/
private function isStsLegacyEndpointUsed($service, $region, $options)
{
return $service === 'sts' && in_array($region, $this->stsLegacyGlobalRegions) && (empty($options['sts_regional_endpoints']) || \UglyRobot\Infinite_Uploads\Aws\Sts\RegionalEndpoints\ConfigurationProvider::unwrap($options['sts_regional_endpoints'])->getEndpointsType() !== 'regional');
}
/**
* S3 legacy us-east-1 endpoint used for valid regions unless option is explicitly
* set to 'regional'
*
* @param string $service
* @param string $region
* @param array $options
* @return bool
*/
private function isS3LegacyEndpointUsed($service, $region, $options)
{
return $service === 's3' && $region === 'us-east-1' && (empty($options['s3_us_east_1_regional_endpoint']) || \UglyRobot\Infinite_Uploads\Aws\S3\RegionalEndpoint\ConfigurationProvider::unwrap($options['s3_us_east_1_regional_endpoint'])->getEndpointsType() !== 'regional');
}
private function getPartitionEndpoint($service)
{
return $this->data['services'][$service]['partitionEndpoint'];
}
private function formatEndpoint($template, $service, $region)
{
return strtr($template, ['{service}' => $service, '{region}' => $region, '{dnsSuffix}' => $this->data['dnsSuffix']]);
}
}

View File

@ -0,0 +1,113 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Endpoint;
use UglyRobot\Infinite_Uploads\JmesPath\Env;
class PartitionEndpointProvider
{
/** @var Partition[] */
private $partitions;
/** @var string */
private $defaultPartition;
/** @var array */
private $options;
/**
* The 'options' parameter accepts the following arguments:
*
* - sts_regional_endpoints: For STS legacy regions, set to 'regional' to
* use regional endpoints, 'legacy' to use the legacy global endpoint.
* Defaults to 'legacy'.
* - s3_us_east_1_regional_endpoint: For S3 us-east-1 region, set to 'regional'
* to use the regional endpoint, 'legacy' to use the legacy global endpoint.
* Defaults to 'legacy'.
*
* @param array $partitions
* @param string $defaultPartition
* @param array $options
*/
public function __construct(array $partitions, $defaultPartition = 'aws', $options = [])
{
$this->partitions = array_map(function (array $definition) {
return new \UglyRobot\Infinite_Uploads\Aws\Endpoint\Partition($definition);
}, array_values($partitions));
$this->defaultPartition = $defaultPartition;
$this->options = $options;
}
public function __invoke(array $args = [])
{
$partition = $this->getPartition(isset($args['region']) ? $args['region'] : '', isset($args['service']) ? $args['service'] : '');
$args['options'] = $this->options;
return $partition($args);
}
/**
* Returns the partition containing the provided region or the default
* partition if no match is found.
*
* @param string $region
* @param string $service
*
* @return Partition
*/
public function getPartition($region, $service)
{
foreach ($this->partitions as $partition) {
if ($partition->isRegionMatch($region, $service)) {
return $partition;
}
}
return $this->getPartitionByName($this->defaultPartition);
}
/**
* Returns the partition with the provided name or null if no partition with
* the provided name can be found.
*
* @param string $name
*
* @return Partition|null
*/
public function getPartitionByName($name)
{
foreach ($this->partitions as $partition) {
if ($name === $partition->getName()) {
return $partition;
}
}
}
/**
* Creates and returns the default SDK partition provider.
*
* @param array $options
* @return PartitionEndpointProvider
*/
public static function defaultProvider($options = [])
{
$data = \UglyRobot\Infinite_Uploads\Aws\load_compiled_json(__DIR__ . '/../data/endpoints.json');
$prefixData = \UglyRobot\Infinite_Uploads\Aws\load_compiled_json(__DIR__ . '/../data/endpoints_prefix_history.json');
$mergedData = self::mergePrefixData($data, $prefixData);
return new self($mergedData['partitions'], 'aws', $options);
}
/**
* Copy endpoint data for other prefixes used by a given service
*
* @param $data
* @param $prefixData
* @return array
*/
public static function mergePrefixData($data, $prefixData)
{
$prefixGroups = $prefixData['prefix-groups'];
foreach ($data["partitions"] as $index => $partition) {
foreach ($prefixGroups as $current => $old) {
$serviceData = \UglyRobot\Infinite_Uploads\JmesPath\Env::search("services.\"{$current}\"", $partition);
if (!empty($serviceData)) {
foreach ($old as $prefix) {
if (empty(\UglyRobot\Infinite_Uploads\JmesPath\Env::search("services.\"{$prefix}\"", $partition))) {
$data["partitions"][$index]["services"][$prefix] = $serviceData;
}
}
}
}
}
return $data;
}
}

View File

@ -0,0 +1,51 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Endpoint;
/**
* Represents a section of the AWS cloud.
*/
interface PartitionInterface
{
/**
* Returns the partition's short name, e.g., 'aws,' 'aws-cn,' or
* 'aws-us-gov.'
*
* @return string
*/
public function getName();
/**
* Determine if this partition contains the provided region. Include the
* name of the service to inspect non-regional endpoints
*
* @param string $region
* @param string $service
*
* @return bool
*/
public function isRegionMatch($region, $service);
/**
* Return the endpoints supported by a given service.
*
* @param string $service Identifier of the service
* whose endpoints should be
* listed (e.g., 's3' or 'ses')
* @param bool $allowNonRegionalEndpoints Set to `true` to include
* endpoints that are not AWS
* regions (e.g., 'local' for
* DynamoDB or
* 'fips-us-gov-west-1' for S3)
*
* @return string[]
*/
public function getAvailableEndpoints($service, $allowNonRegionalEndpoints = false);
/**
* A partition must be invokable as an endpoint provider.
*
* @see EndpointProvider
*
* @param array $args
* @return array
*/
public function __invoke(array $args = []);
}

View File

@ -0,0 +1,37 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Endpoint;
/**
* Provides endpoints based on an endpoint pattern configuration array.
*/
class PatternEndpointProvider
{
/** @var array */
private $patterns;
/**
* @param array $patterns Hash of endpoint patterns mapping to endpoint
* configurations.
*/
public function __construct(array $patterns)
{
$this->patterns = $patterns;
}
public function __invoke(array $args = [])
{
$service = isset($args['service']) ? $args['service'] : '';
$region = isset($args['region']) ? $args['region'] : '';
$keys = ["{$region}/{$service}", "{$region}/*", "*/{$service}", "*/*"];
foreach ($keys as $key) {
if (isset($this->patterns[$key])) {
return $this->expand($this->patterns[$key], isset($args['scheme']) ? $args['scheme'] : 'https', $service, $region);
}
}
return null;
}
private function expand(array $config, $scheme, $service, $region)
{
$config['endpoint'] = $scheme . '://' . strtr($config['endpoint'], ['{service}' => $service, '{region}' => $region]);
return $config;
}
}