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']]); } }