updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -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,13 +128,23 @@ 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);
$variant = $this->getVariant($options, $data);
if (isset($variant['hostname'])) {
$template = $variant['hostname'];
} else {
$template = isset($data['hostname']) ? $data['hostname'] : '';
}
$dnsSuffix = isset($variant['dnsSuffix'])
? $variant['dnsSuffix']
: $this->data['dnsSuffix'];
return [
'endpoint' => "{$scheme}://" . $this->formatEndpoint(
isset($data['hostname']) ? $data['hostname'] : '',
$template,
$service,
$region
$region,
$dnsSuffix
),
'signatureVersion' => $this->getSignatureVersion($data),
'signingRegion' => isset($data['credentialScope']['region'])
@@ -116,12 +156,11 @@ final class Partition implements ArrayAccess, PartitionInterface
];
}
private function getEndpointData($service, $region)
private function getEndpointData($service, $region, $options)
{
$resolved = $this->resolveRegion($service, $region);
$data = isset($this->data['services'][$service]['endpoints'][$resolved])
? $this->data['services'][$service]['endpoints'][$resolved]
$defaultRegion = $this->resolveRegion($service, $region, $options);
$data = isset($this->data['services'][$service]['endpoints'][$defaultRegion])
? $this->data['services'][$service]['endpoints'][$defaultRegion]
: [];
$data += isset($this->data['services'][$service]['defaults'])
? $this->data['services'][$service]['defaults']
@@ -151,9 +190,18 @@ 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 (isset($this->data['services'][$service]['endpoints'][$region])
&& $this->isFipsEndpointUsed($region)
) {
return $region;
}
if ($this->isServicePartitionGlobal($service)
|| $this->isStsLegacyEndpointUsed($service, $region, $options)
|| $this->isS3LegacyEndpointUsed($service, $region, $options)
) {
return $this->getPartitionEndpoint($service);
}
@@ -167,17 +215,102 @@ 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'];
}
private function formatEndpoint($template, $service, $region)
private function formatEndpoint($template, $service, $region, $dnsSuffix)
{
return strtr($template, [
'{service}' => $service,
'{region}' => $region,
'{dnsSuffix}' => $this->data['dnsSuffix'],
'{dnsSuffix}' => $dnsSuffix,
]);
}
/**
* @param $region
* @return bool
*/
private function isFipsEndpointUsed($region)
{
return strpos($region, "fips") !== false;
}
/**
* @param array $options
* @param array $data
* @return array
*/
private function getVariant(array $options, array $data)
{
$variantTags = [];
if (isset($options['use_fips_endpoint'])) {
if ($options['use_fips_endpoint']->isUseFipsEndpoint()) {
$variantTags[] = 'fips';
}
}
if (isset($options['use_dual_stack_endpoint'])) {
if ($options['use_dual_stack_endpoint']->isUseDualStackEndpoint()) {
$variantTags[] = 'dualstack';
}
}
if (!empty($variantTags)) {
if (isset($data['variants'])) {
foreach ($data['variants'] as $variant) {
if (array_count_values($variant['tags']) == array_count_values($variantTags)) {
return $variant;
}
}
}
if (isset($this->data['defaults']['variants'])) {
foreach ($this->data['defaults']['variants'] as $variant) {
if (array_count_values($variant['tags']) == array_count_values($variantTags)) {
return $variant;
}
}
}
}
}
}

View File

@@ -9,13 +9,33 @@ class PartitionEndpointProvider
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 = [])
@@ -24,6 +44,7 @@ class PartitionEndpointProvider
isset($args['region']) ? $args['region'] : '',
isset($args['service']) ? $args['service'] : ''
);
$args['options'] = $this->options;
return $partition($args);
}
@@ -68,15 +89,16 @@ 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(__DIR__ . '/../data/endpoints.json');
$prefixData = \Aws\load_compiled_json(__DIR__ . '/../data/endpoints_prefix_history.json');
$mergedData = self::mergePrefixData($data, $prefixData);
return new self($mergedData['partitions']);
return new self($mergedData['partitions'], 'aws', $options);
}
/**
@@ -92,10 +114,10 @@ class PartitionEndpointProvider
foreach ($data["partitions"] as $index => $partition) {
foreach ($prefixGroups as $current => $old) {
$serviceData = Env::search("services.{$current}", $partition);
$serviceData = Env::search("services.\"{$current}\"", $partition);
if (!empty($serviceData)) {
foreach ($old as $prefix) {
if (empty(Env::search("services.{$prefix}", $partition))) {
if (empty(Env::search("services.\"{$prefix}\"", $partition))) {
$data["partitions"][$index]["services"][$prefix] = $serviceData;
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Aws\Endpoint\UseDualstackEndpoint;
use Aws;
use Aws\Endpoint\UseDualstackEndpoint\Exception\ConfigurationException;
class Configuration implements ConfigurationInterface
{
private $useDualstackEndpoint;
public function __construct($useDualstackEndpoint, $region)
{
$this->useDualstackEndpoint = Aws\boolean_value($useDualstackEndpoint);
if (is_null($this->useDualstackEndpoint)) {
throw new ConfigurationException("'use_dual_stack_endpoint' config option"
. " must be a boolean value.");
}
if ($this->useDualstackEndpoint == true
&& (strpos($region, "iso-") !== false || strpos($region, "-iso") !== false)
) {
throw new ConfigurationException("Dual-stack is not supported in ISO regions"); }
}
/**
* {@inheritdoc}
*/
public function isUseDualstackEndpoint()
{
return $this->useDualstackEndpoint;
}
/**
* {@inheritdoc}
*/
public function toArray()
{
return [
'use_dual_stack_endpoint' => $this->isUseDualstackEndpoint(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Aws\Endpoint\UseDualstackEndpoint;
interface ConfigurationInterface
{
/**
* Returns whether or not to use a DUALSTACK endpoint
*
* @return bool
*/
public function isUseDualstackEndpoint();
/**
* Returns the configuration as an associative array
*
* @return array
*/
public function toArray();
}

View File

@@ -0,0 +1,173 @@
<?php
namespace Aws\Endpoint\UseDualstackEndpoint;
use Aws\AbstractConfigurationProvider;
use Aws\CacheInterface;
use Aws\ConfigurationProviderInterface;
use Aws\Endpoint\UseDualstackEndpoint\Exception\ConfigurationException;
use GuzzleHttp\Promise;
/**
* A configuration provider is a function that returns a promise that is
* fulfilled with a {@see \Aws\Endpoint\UseDualstackEndpoint\onfigurationInterface}
* or rejected with an {@see \Aws\Endpoint\UseDualstackEndpoint\ConfigurationException}.
*
* <code>
* use Aws\Endpoint\UseDualstackEndpoint\ConfigurationProvider;
* $provider = ConfigurationProvider::defaultProvider();
* // Returns a ConfigurationInterface or throws.
* $config = $provider()->wait();
* </code>
*
* Configuration providers can be composed to create configuration using
* conditional logic that can create different configurations in different
* environments. You can compose multiple providers into a single provider using
* {@see Aws\Endpoint\UseDualstackEndpoint\ConfigurationProvider::chain}. This function
* accepts providers as variadic arguments and returns a new function that will
* invoke each provider until a successful configuration is returned.
*
* <code>
* // First try an INI file at this location.
* $a = ConfigurationProvider::ini(null, '/path/to/file.ini');
* // Then try an INI file at this location.
* $b = ConfigurationProvider::ini(null, '/path/to/other-file.ini');
* // Then try loading from environment variables.
* $c = ConfigurationProvider::env();
* // Combine the three providers together.
* $composed = ConfigurationProvider::chain($a, $b, $c);
* // Returns a promise that is fulfilled with a configuration or throws.
* $promise = $composed();
* // Wait on the configuration to resolve.
* $config = $promise->wait();
* </code>
*/
class ConfigurationProvider extends AbstractConfigurationProvider
implements ConfigurationProviderInterface
{
const ENV_USE_DUAL_STACK_ENDPOINT = 'AWS_USE_DUALSTACK_ENDPOINT';
const INI_USE_DUAL_STACK_ENDPOINT = 'use_dualstack_endpoint';
public static $cacheKey = 'aws_cached_use_dualstack_endpoint_config';
protected static $interfaceClass = ConfigurationInterface::class;
protected static $exceptionClass = ConfigurationException::class;
/**
* Create a default config provider that first checks for environment
* variables, then checks for a specified profile in the environment-defined
* config file location (env variable is 'AWS_CONFIG_FILE', file location
* defaults to ~/.aws/config), then checks for the "default" profile in the
* environment-defined config file location, and failing those uses a default
* fallback set of configuration options.
*
* This provider is automatically wrapped in a memoize function that caches
* previously provided config options.
*
* @param array $config
*
* @return callable
*/
public static function defaultProvider(array $config = [])
{
$region = $config['region'];
$configProviders = [self::env($region)];
if (
!isset($config['use_aws_shared_config_files'])
|| $config['use_aws_shared_config_files'] != false
) {
$configProviders[] = self::ini($region);
}
$configProviders[] = self::fallback($region);
$memo = self::memoize(
call_user_func_array([ConfigurationProvider::class, 'chain'], $configProviders)
);
if (isset($config['use_dual_stack_endpoint'])
&& $config['use_dual_stack_endpoint'] instanceof CacheInterface
) {
return self::cache($memo, $config['use_dual_stack_endpoint'], self::$cacheKey);
}
return $memo;
}
/**
* Provider that creates config from environment variables.
*
* @return callable
*/
public static function env($region)
{
return function () use ($region) {
// Use config from environment variables, if available
$useDualstackEndpoint = getenv(self::ENV_USE_DUAL_STACK_ENDPOINT);
if (!empty($useDualstackEndpoint)) {
return Promise\Create::promiseFor(
new Configuration($useDualstackEndpoint, $region)
);
}
return self::reject('Could not find environment variable config'
. ' in ' . self::ENV_USE_DUAL_STACK_ENDPOINT);
};
}
/**
* Config provider that creates config using a config file whose location
* is specified by an environment variable 'AWS_CONFIG_FILE', defaulting to
* ~/.aws/config if not specified
*
* @param string|null $profile Profile to use. If not specified will use
* the "default" profile.
* @param string|null $filename If provided, uses a custom filename rather
* than looking in the default directory.
*
* @return callable
*/
public static function ini($region, $profile = null, $filename = null)
{
$filename = $filename ?: (self::getDefaultConfigFilename());
$profile = $profile ?: (getenv(self::ENV_PROFILE) ?: 'default');
return function () use ($region, $profile, $filename) {
if (!@is_readable($filename)) {
return self::reject("Cannot read configuration from $filename");
}
// Use INI_SCANNER_NORMAL instead of INI_SCANNER_TYPED for PHP 5.5 compatibility
$data = \Aws\parse_ini_file($filename, true, INI_SCANNER_NORMAL);
if ($data === false) {
return self::reject("Invalid config file: $filename");
}
if (!isset($data[$profile])) {
return self::reject("'$profile' not found in config file");
}
if (!isset($data[$profile][self::INI_USE_DUAL_STACK_ENDPOINT])) {
return self::reject("Required use dualstack endpoint config values
not present in INI profile '{$profile}' ({$filename})");
}
// INI_SCANNER_NORMAL parses false-y values as an empty string
if ($data[$profile][self::INI_USE_DUAL_STACK_ENDPOINT] === "") {
$data[$profile][self::INI_USE_DUAL_STACK_ENDPOINT] = false;
}
return Promise\Create::promiseFor(
new Configuration($data[$profile][self::INI_USE_DUAL_STACK_ENDPOINT], $region)
);
};
}
/**
* Fallback config options when other sources are not set.
*
* @return callable
*/
public static function fallback($region)
{
return function () use ($region) {
return Promise\Create::promiseFor(new Configuration(false, $region));
};
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Aws\Endpoint\UseDualstackEndpoint\Exception;
use Aws\HasMonitoringEventsTrait;
use Aws\MonitoringEventsInterface;
/**
* Represents an error interacting with configuration for useDualstackRegion
*/
class ConfigurationException extends \RuntimeException implements
MonitoringEventsInterface
{
use HasMonitoringEventsTrait;
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Aws\Endpoint\UseFipsEndpoint;
use Aws;
use Aws\ClientResolver;
use Aws\Endpoint\UseFipsEndpoint\Exception\ConfigurationException;
class Configuration implements ConfigurationInterface
{
private $useFipsEndpoint;
public function __construct($useFipsEndpoint)
{
$this->useFipsEndpoint = Aws\boolean_value($useFipsEndpoint);
if (is_null($this->useFipsEndpoint)) {
throw new ConfigurationException("'use_fips_endpoint' config option"
. " must be a boolean value.");
}
}
/**
* {@inheritdoc}
*/
public function isUseFipsEndpoint()
{
return $this->useFipsEndpoint;
}
/**
* {@inheritdoc}
*/
public function toArray()
{
return [
'use_fips_endpoint' => $this->isUseFipsEndpoint(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Aws\Endpoint\UseFipsEndpoint;
interface ConfigurationInterface
{
/**
* Returns whether or not to use a FIPS endpoint
*
* @return bool
*/
public function isUseFipsEndpoint();
/**
* Returns the configuration as an associative array
*
* @return array
*/
public function toArray();
}

View File

@@ -0,0 +1,179 @@
<?php
namespace Aws\Endpoint\UseFipsEndpoint;
use Aws\AbstractConfigurationProvider;
use Aws\CacheInterface;
use Aws\ConfigurationProviderInterface;
use Aws\Endpoint\UseFipsEndpoint\Exception\ConfigurationException;
use GuzzleHttp\Promise;
/**
* A configuration provider is a function that returns a promise that is
* fulfilled with a {@see \Aws\Endpoint\UseFipsEndpoint\onfigurationInterface}
* or rejected with an {@see \Aws\Endpoint\UseFipsEndpoint\ConfigurationException}.
*
* <code>
* use Aws\Endpoint\UseFipsEndpoint\ConfigurationProvider;
* $provider = ConfigurationProvider::defaultProvider();
* // Returns a ConfigurationInterface or throws.
* $config = $provider()->wait();
* </code>
*
* Configuration providers can be composed to create configuration using
* conditional logic that can create different configurations in different
* environments. You can compose multiple providers into a single provider using
* {@see Aws\Endpoint\UseFipsEndpoint\ConfigurationProvider::chain}. This function
* accepts providers as variadic arguments and returns a new function that will
* invoke each provider until a successful configuration is returned.
*
* <code>
* // First try an INI file at this location.
* $a = ConfigurationProvider::ini(null, '/path/to/file.ini');
* // Then try an INI file at this location.
* $b = ConfigurationProvider::ini(null, '/path/to/other-file.ini');
* // Then try loading from environment variables.
* $c = ConfigurationProvider::env();
* // Combine the three providers together.
* $composed = ConfigurationProvider::chain($a, $b, $c);
* // Returns a promise that is fulfilled with a configuration or throws.
* $promise = $composed();
* // Wait on the configuration to resolve.
* $config = $promise->wait();
* </code>
*/
class ConfigurationProvider extends AbstractConfigurationProvider
implements ConfigurationProviderInterface
{
const ENV_USE_FIPS_ENDPOINT = 'AWS_USE_FIPS_ENDPOINT';
const INI_USE_FIPS_ENDPOINT = 'use_fips_endpoint';
public static $cacheKey = 'aws_cached_use_fips_endpoint_config';
protected static $interfaceClass = ConfigurationInterface::class;
protected static $exceptionClass = ConfigurationException::class;
/**
* Create a default config provider that first checks for environment
* variables, then checks for a specified profile in the environment-defined
* config file location (env variable is 'AWS_CONFIG_FILE', file location
* defaults to ~/.aws/config), then checks for the "default" profile in the
* environment-defined config file location, and failing those uses a default
* fallback set of configuration options.
*
* This provider is automatically wrapped in a memoize function that caches
* previously provided config options.
*
* @param array $config
*
* @return callable
*/
public static function defaultProvider(array $config = [])
{
$configProviders = [self::env()];
if (
!isset($config['use_aws_shared_config_files'])
|| $config['use_aws_shared_config_files'] != false
) {
$configProviders[] = self::ini();
}
$configProviders[] = self::fallback($config['region']);
$memo = self::memoize(
call_user_func_array([ConfigurationProvider::class, 'chain'], $configProviders)
);
if (isset($config['use_fips_endpoint'])
&& $config['use_fips_endpoint'] instanceof CacheInterface
) {
return self::cache($memo, $config['use_fips_endpoint'], self::$cacheKey);
}
return $memo;
}
/**
* Provider that creates config from environment variables.
*
* @return callable
*/
public static function env()
{
return function () {
// Use config from environment variables, if available
$useFipsEndpoint = getenv(self::ENV_USE_FIPS_ENDPOINT);
if (!empty($useFipsEndpoint)) {
return Promise\Create::promiseFor(
new Configuration($useFipsEndpoint)
);
}
return self::reject('Could not find environment variable config'
. ' in ' . self::ENV_USE_FIPS_ENDPOINT);
};
}
/**
* Config provider that creates config using a config file whose location
* is specified by an environment variable 'AWS_CONFIG_FILE', defaulting to
* ~/.aws/config if not specified
*
* @param string|null $profile Profile to use. If not specified will use
* the "default" profile.
* @param string|null $filename If provided, uses a custom filename rather
* than looking in the default directory.
*
* @return callable
*/
public static function ini($profile = null, $filename = null)
{
$filename = $filename ?: (self::getDefaultConfigFilename());
$profile = $profile ?: (getenv(self::ENV_PROFILE) ?: 'default');
return function () use ($profile, $filename) {
if (!@is_readable($filename)) {
return self::reject("Cannot read configuration from $filename");
}
// Use INI_SCANNER_NORMAL instead of INI_SCANNER_TYPED for PHP 5.5 compatibility
$data = \Aws\parse_ini_file($filename, true, INI_SCANNER_NORMAL);
if ($data === false) {
return self::reject("Invalid config file: $filename");
}
if (!isset($data[$profile])) {
return self::reject("'$profile' not found in config file");
}
if (!isset($data[$profile][self::INI_USE_FIPS_ENDPOINT])) {
return self::reject("Required use fips endpoint config values
not present in INI profile '{$profile}' ({$filename})");
}
// INI_SCANNER_NORMAL parses false-y values as an empty string
if ($data[$profile][self::INI_USE_FIPS_ENDPOINT] === "") {
$data[$profile][self::INI_USE_FIPS_ENDPOINT] = false;
}
return Promise\Create::promiseFor(
new Configuration($data[$profile][self::INI_USE_FIPS_ENDPOINT])
);
};
}
/**
* Fallback config options when other sources are not set.
*
* @return callable
*/
public static function fallback($region)
{
return function () use ($region) {
$isFipsPseudoRegion = strpos($region, 'fips-') !== false
|| strpos($region, '-fips') !== false;
if ($isFipsPseudoRegion){
$configuration = new Configuration(true);
} else {
$configuration = new Configuration(false);
}
return Promise\Create::promiseFor($configuration);
};
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Aws\Endpoint\UseFipsEndpoint\Exception;
use Aws\HasMonitoringEventsTrait;
use Aws\MonitoringEventsInterface;
/**
* Represents an error interacting with configuration for useFipsRegion
*/
class ConfigurationException extends \RuntimeException implements
MonitoringEventsInterface
{
use HasMonitoringEventsTrait;
}