OutpostsAccessPointArn.php 3.6 KB

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