PluginProbe
Media Cloud Sync / 1.3.11
Media Cloud Sync v1.3.11
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / S3 / EndpointRegionHelperTrait.php

EndpointRegionHelperTrait.php in Media Cloud Sync 1.3.11, at includes/sdk/s3/Aws/S3/EndpointRegionHelperTrait.php

72 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\S3;
4
5 use Dudlewebs\WPMCS\s3\Aws\Api\Service;
6 use Dudlewebs\WPMCS\s3\Aws\Arn\ArnInterface;
7 use Dudlewebs\WPMCS\s3\Aws\Arn\S3\OutpostsArnInterface;
8 use Dudlewebs\WPMCS\s3\Aws\Endpoint\PartitionEndpointProvider;
9 use Dudlewebs\WPMCS\s3\Aws\Exception\InvalidRegionException;
10 /**
11 * @internal
12 */
13 trait EndpointRegionHelperTrait
14 {
15 /** @var array */
16 private $config;
17 /** @var PartitionEndpointProvider */
18 private $partitionProvider;
19 /** @var string */
20 private $region;
21 /** @var Service */
22 private $service;
23 private function getPartitionSuffix(ArnInterface $arn, PartitionEndpointProvider $provider)
24 {
25 $partition = $provider->getPartition($arn->getRegion(), $arn->getService());
26 return $partition->getDnsSuffix();
27 }
28 private function getSigningRegion($region, $service, PartitionEndpointProvider $provider)
29 {
30 $partition = $provider->getPartition($region, $service);
31 $data = $partition->toArray();
32 if (isset($data['services'][$service]['endpoints'][$region]['credentialScope']['region'])) {
33 return $data['services'][$service]['endpoints'][$region]['credentialScope']['region'];
34 }
35 return $region;
36 }
37 private function isMatchingSigningRegion($arnRegion, $clientRegion, $service, PartitionEndpointProvider $provider)
38 {
39 $arnRegion = \Dudlewebs\WPMCS\s3\Aws\strip_fips_pseudo_regions(\strtolower($arnRegion));
40 $clientRegion = \strtolower($clientRegion);
41 if ($arnRegion === $clientRegion) {
42 return \true;
43 }
44 if ($this->getSigningRegion($clientRegion, $service, $provider) === $arnRegion) {
45 return \true;
46 }
47 return \false;
48 }
49 private function validateFipsConfigurations(ArnInterface $arn)
50 {
51 $useFipsEndpoint = !empty($this->config['use_fips_endpoint']);
52 if ($arn instanceof OutpostsArnInterface) {
53 if (empty($this->config['use_arn_region']) || !$this->config['use_arn_region']->isUseArnRegion()) {
54 $region = $this->region;
55 } else {
56 $region = $arn->getRegion();
57 }
58 if (\Dudlewebs\WPMCS\s3\Aws\is_fips_pseudo_region($region)) {
59 throw new InvalidRegionException('Fips is currently not supported with S3 Outposts access' . ' points. Please provide a non-fips region or do not supply an' . ' access point ARN.');
60 }
61 }
62 }
63 private function validateMatchingRegion(ArnInterface $arn)
64 {
65 if (!$this->isMatchingSigningRegion($arn->getRegion(), $this->region, $this->service->getEndpointPrefix(), $this->partitionProvider)) {
66 if (empty($this->config['use_arn_region']) || !$this->config['use_arn_region']->isUseArnRegion()) {
67 throw new InvalidRegionException('The region' . " specified in the ARN (" . $arn->getRegion() . ") does not match the client region (" . "{$this->region}).");
68 }
69 }
70 }
71 }
72