AccessPointArn.php
11 months ago
BucketArnInterface.php
11 months ago
MultiRegionAccessPointArn.php
11 months ago
OutpostsAccessPointArn.php
11 months ago
OutpostsArnInterface.php
11 months ago
OutpostsBucketArn.php
11 months ago
OutpostsAccessPointArn.php
111 lines
| 1 | <?php |
| 2 | namespace Aws\Arn\S3; |
| 3 | |
| 4 | use Aws\Arn\AccessPointArn as BaseAccessPointArn; |
| 5 | use Aws\Arn\AccessPointArnInterface; |
| 6 | use Aws\Arn\Arn; |
| 7 | use Aws\Arn\Exception\InvalidArnException; |
| 8 | |
| 9 | /** |
| 10 | * This class represents an S3 Outposts access point ARN, which is in the |
| 11 | * following format: |
| 12 | * |
| 13 | * arn:{partition}:s3-outposts:{region}:{accountId}:outpost:{outpostId}:accesspoint:{accesspointName} |
| 14 | * |
| 15 | * ':' and '/' can be used interchangeably as delimiters for components after |
| 16 | * the account ID. |
| 17 | * |
| 18 | * @internal |
| 19 | */ |
| 20 | class OutpostsAccessPointArn extends BaseAccessPointArn implements |
| 21 | AccessPointArnInterface, |
| 22 | OutpostsArnInterface |
| 23 | { |
| 24 | public static function parse($string) |
| 25 | { |
| 26 | $data = parent::parse($string); |
| 27 | return self::parseOutpostData($data); |
| 28 | } |
| 29 | |
| 30 | public function getOutpostId() |
| 31 | { |
| 32 | return $this->data['outpost_id']; |
| 33 | } |
| 34 | |
| 35 | public function getAccesspointName() |
| 36 | { |
| 37 | return $this->data['accesspoint_name']; |
| 38 | } |
| 39 | |
| 40 | private static function parseOutpostData(array $data) |
| 41 | { |
| 42 | $resourceData = preg_split("/[\/:]/", $data['resource_id']); |
| 43 | |
| 44 | $data['outpost_id'] = isset($resourceData[0]) |
| 45 | ? $resourceData[0] |
| 46 | : null; |
| 47 | $data['accesspoint_type'] = isset($resourceData[1]) |
| 48 | ? $resourceData[1] |
| 49 | : null; |
| 50 | $data['accesspoint_name'] = isset($resourceData[2]) |
| 51 | ? $resourceData[2] |
| 52 | : null; |
| 53 | if (isset($resourceData[3])) { |
| 54 | $data['resource_extra'] = implode(':', array_slice($resourceData, 3)); |
| 55 | } |
| 56 | |
| 57 | return $data; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Validation specific to OutpostsAccessPointArn. Note this uses the base Arn |
| 62 | * class validation instead of the direct parent due to it having slightly |
| 63 | * differing requirements from its parent. |
| 64 | * |
| 65 | * @param array $data |
| 66 | */ |
| 67 | public static function validate(array $data) |
| 68 | { |
| 69 | Arn::validate($data); |
| 70 | |
| 71 | if (($data['service'] !== 's3-outposts')) { |
| 72 | throw new InvalidArnException("The 3rd component of an S3 Outposts" |
| 73 | . " access point ARN represents the service and must be" |
| 74 | . " 's3-outposts'."); |
| 75 | } |
| 76 | |
| 77 | self::validateRegion($data, 'S3 Outposts access point ARN'); |
| 78 | self::validateAccountId($data, 'S3 Outposts access point ARN'); |
| 79 | |
| 80 | if (($data['resource_type'] !== 'outpost')) { |
| 81 | throw new InvalidArnException("The 6th component of an S3 Outposts" |
| 82 | . " access point ARN represents the resource type and must be" |
| 83 | . " 'outpost'."); |
| 84 | } |
| 85 | |
| 86 | if (!self::isValidHostLabel($data['outpost_id'])) { |
| 87 | throw new InvalidArnException("The 7th component of an S3 Outposts" |
| 88 | . " access point ARN is required, represents the outpost ID, and" |
| 89 | . " must be a valid host label."); |
| 90 | } |
| 91 | |
| 92 | if ($data['accesspoint_type'] !== 'accesspoint') { |
| 93 | throw new InvalidArnException("The 8th component of an S3 Outposts" |
| 94 | . " access point ARN must be 'accesspoint'"); |
| 95 | } |
| 96 | |
| 97 | if (!self::isValidHostLabel($data['accesspoint_name'])) { |
| 98 | throw new InvalidArnException("The 9th component of an S3 Outposts" |
| 99 | . " access point ARN is required, represents the accesspoint name," |
| 100 | . " and must be a valid host label."); |
| 101 | } |
| 102 | |
| 103 | if (!empty($data['resource_extra'])) { |
| 104 | throw new InvalidArnException("An S3 Outposts access point ARN" |
| 105 | . " should only have 9 components, delimited by the characters" |
| 106 | . " ':' and '/'. '{$data['resource_extra']}' was found after the" |
| 107 | . " 9th component."); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 |