diff options
Diffstat (limited to 'aws/aws-sdk-php/src/Endpoint/Partition.php')
-rw-r--r-- | aws/aws-sdk-php/src/Endpoint/Partition.php | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/aws/aws-sdk-php/src/Endpoint/Partition.php b/aws/aws-sdk-php/src/Endpoint/Partition.php index ad003ddc..5125485b 100644 --- a/aws/aws-sdk-php/src/Endpoint/Partition.php +++ b/aws/aws-sdk-php/src/Endpoint/Partition.php @@ -130,12 +130,21 @@ final class Partition implements ArrayAccess, PartitionInterface $scheme = isset($args['scheme']) ? $args['scheme'] : 'https'; $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']) @@ -251,12 +260,12 @@ final class Partition implements ArrayAccess, PartitionInterface 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, ]); } @@ -268,4 +277,40 @@ final class Partition implements ArrayAccess, PartitionInterface { 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; + } + } + } + } + } } |