mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-08-14 02:27:23 -07:00
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:
parent
ad0726e41e
commit
e6d7753dc8
1095 changed files with 45088 additions and 2911 deletions
|
@ -3,6 +3,8 @@ namespace Aws\Endpoint;
|
|||
|
||||
use ArrayAccess;
|
||||
use Aws\HasDataTrait;
|
||||
use Aws\Sts\RegionalEndpoints\ConfigurationProvider;
|
||||
use Aws\S3\RegionalEndpoint\ConfigurationProvider as S3ConfigurationProvider;
|
||||
use InvalidArgumentException as Iae;
|
||||
|
||||
/**
|
||||
|
@ -12,6 +14,25 @@ final class Partition implements ArrayAccess, 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:
|
||||
*
|
||||
|
@ -52,6 +73,15 @@ final class Partition implements ArrayAccess, PartitionInterface
|
|||
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])
|
||||
|
@ -98,7 +128,8 @@ final class Partition implements ArrayAccess, PartitionInterface
|
|||
$service = isset($args['service']) ? $args['service'] : '';
|
||||
$region = isset($args['region']) ? $args['region'] : '';
|
||||
$scheme = isset($args['scheme']) ? $args['scheme'] : 'https';
|
||||
$data = $this->getEndpointData($service, $region);
|
||||
$options = isset($args['options']) ? $args['options'] : [];
|
||||
$data = $this->getEndpointData($service, $region, $options);
|
||||
|
||||
return [
|
||||
'endpoint' => "{$scheme}://" . $this->formatEndpoint(
|
||||
|
@ -116,10 +147,9 @@ final class Partition implements ArrayAccess, PartitionInterface
|
|||
];
|
||||
}
|
||||
|
||||
private function getEndpointData($service, $region)
|
||||
private function getEndpointData($service, $region, $options)
|
||||
{
|
||||
|
||||
$resolved = $this->resolveRegion($service, $region);
|
||||
$resolved = $this->resolveRegion($service, $region, $options);
|
||||
$data = isset($this->data['services'][$service]['endpoints'][$resolved])
|
||||
? $this->data['services'][$service]['endpoints'][$resolved]
|
||||
: [];
|
||||
|
@ -151,9 +181,12 @@ final class Partition implements ArrayAccess, PartitionInterface
|
|||
return array_shift($possibilities);
|
||||
}
|
||||
|
||||
private function resolveRegion($service, $region)
|
||||
private function resolveRegion($service, $region, $options)
|
||||
{
|
||||
if ($this->isServicePartitionGlobal($service)) {
|
||||
if ($this->isServicePartitionGlobal($service)
|
||||
|| $this->isStsLegacyEndpointUsed($service, $region, $options)
|
||||
|| $this->isS3LegacyEndpointUsed($service, $region, $options)
|
||||
) {
|
||||
return $this->getPartitionEndpoint($service);
|
||||
}
|
||||
|
||||
|
@ -167,6 +200,46 @@ final class Partition implements ArrayAccess, PartitionInterface
|
|||
&& 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'])
|
||||
|| 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'])
|
||||
|| S3ConfigurationProvider::unwrap(
|
||||
$options['s3_us_east_1_regional_endpoint']
|
||||
)->getEndpointsType() !== 'regional'
|
||||
);
|
||||
}
|
||||
|
||||
private function getPartitionEndpoint($service)
|
||||
{
|
||||
return $this->data['services'][$service]['partitionEndpoint'];
|
||||
|
|
|
@ -1,19 +1,41 @@
|
|||
<?php
|
||||
namespace Aws\Endpoint;
|
||||
|
||||
use JmesPath\Env;
|
||||
|
||||
class PartitionEndpointProvider
|
||||
{
|
||||
/** @var Partition[] */
|
||||
private $partitions;
|
||||
/** @var string */
|
||||
private $defaultPartition;
|
||||
/** @var array */
|
||||
private $options;
|
||||
|
||||
public function __construct(array $partitions, $defaultPartition = 'aws')
|
||||
{
|
||||
/**
|
||||
* 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 Partition($definition);
|
||||
}, array_values($partitions));
|
||||
$this->defaultPartition = $defaultPartition;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function __invoke(array $args = [])
|
||||
|
@ -22,6 +44,7 @@ class PartitionEndpointProvider
|
|||
isset($args['region']) ? $args['region'] : '',
|
||||
isset($args['service']) ? $args['service'] : ''
|
||||
);
|
||||
$args['options'] = $this->options;
|
||||
|
||||
return $partition($args);
|
||||
}
|
||||
|
@ -66,12 +89,42 @@ class PartitionEndpointProvider
|
|||
/**
|
||||
* Creates and returns the default SDK partition provider.
|
||||
*
|
||||
* @param array $options
|
||||
* @return PartitionEndpointProvider
|
||||
*/
|
||||
public static function defaultProvider()
|
||||
public static function defaultProvider($options = [])
|
||||
{
|
||||
$data = \Aws\load_compiled_json(dirname(__FILE__) . '/../data/endpoints.json');
|
||||
$data = \Aws\load_compiled_json(__DIR__ . '/../data/endpoints.json');
|
||||
$prefixData = \Aws\load_compiled_json(__DIR__ . '/../data/endpoints_prefix_history.json');
|
||||
$mergedData = self::mergePrefixData($data, $prefixData);
|
||||
|
||||
return new self($data['partitions']);
|
||||
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 = Env::search("services.\"{$current}\"", $partition);
|
||||
if (!empty($serviceData)) {
|
||||
foreach ($old as $prefix) {
|
||||
if (empty(Env::search("services.\"{$prefix}\"", $partition))) {
|
||||
$data["partitions"][$index]["services"][$prefix] = $serviceData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue