Class: Aws::ARN
- Inherits:
-
Object
- Object
- Aws::ARN
- Defined in:
- lib/aws-sdk-core/arn.rb
Overview
Create and provide access to components of Amazon Resource Names (ARN).
You can create an ARN and access it’s components like the following:
arn = Aws::ARN.new(
partition: 'aws',
service: 's3',
region: 'us-west-2',
account_id: '12345678910',
resource: 'foo/bar'
)
# => #<Aws::ARN ...>
arn.to_s
# => "arn:aws:s3:us-west-2:12345678910:foo/bar"
arn.partition
# => 'aws'
arn.service
# => 's3'
arn.resource
# => foo/bar
# Note: parser available for parsing resource details
@see Aws::ARNParser#parse_resource
Instance Attribute Summary collapse
- #account_id ⇒ String readonly
- #partition ⇒ String readonly
- #region ⇒ String readonly
- #resource ⇒ String readonly
- #service ⇒ String readonly
Instance Method Summary collapse
-
#as_json(_options = nil) ⇒ Hash
Return the ARN as JSON.
-
#initialize(options = {}) ⇒ ARN
constructor
A new instance of ARN.
-
#to_h ⇒ Hash
Return the ARN as a hash.
-
#to_s ⇒ String
Return the ARN format in string.
-
#valid? ⇒ Boolean
Validates ARN contains non-empty required components.
Constructor Details
#initialize(options = {}) ⇒ ARN
Returns a new instance of ARN.
39 40 41 42 43 44 45 |
# File 'lib/aws-sdk-core/arn.rb', line 39 def initialize( = {}) @partition = [:partition] @service = [:service] @region = [:region] @account_id = [:account_id] @resource = [:resource] end |
Instance Attribute Details
#account_id ⇒ String (readonly)
57 58 59 |
# File 'lib/aws-sdk-core/arn.rb', line 57 def account_id @account_id end |
#partition ⇒ String (readonly)
48 49 50 |
# File 'lib/aws-sdk-core/arn.rb', line 48 def partition @partition end |
#region ⇒ String (readonly)
54 55 56 |
# File 'lib/aws-sdk-core/arn.rb', line 54 def region @region end |
#resource ⇒ String (readonly)
60 61 62 |
# File 'lib/aws-sdk-core/arn.rb', line 60 def resource @resource end |
#service ⇒ String (readonly)
51 52 53 |
# File 'lib/aws-sdk-core/arn.rb', line 51 def service @service end |
Instance Method Details
#as_json(_options = nil) ⇒ Hash
Return the ARN as JSON
95 96 97 98 99 100 101 102 103 |
# File 'lib/aws-sdk-core/arn.rb', line 95 def as_json( = nil) { 'partition' => @partition, 'service' => @service, 'region' => @region, 'accountId' => @account_id, 'resource' => @resource } end |
#to_h ⇒ Hash
Return the ARN as a hash
82 83 84 85 86 87 88 89 90 |
# File 'lib/aws-sdk-core/arn.rb', line 82 def to_h { partition: @partition, service: @service, region: @region, account_id: @account_id, resource: @resource } end |
#to_s ⇒ String
Return the ARN format in string
75 76 77 |
# File 'lib/aws-sdk-core/arn.rb', line 75 def to_s "arn:#{partition}:#{service}:#{region}:#{account_id}:#{resource}" end |
#valid? ⇒ Boolean
Validates ARN contains non-empty required components. Region and account_id can be optional.
66 67 68 69 70 |
# File 'lib/aws-sdk-core/arn.rb', line 66 def valid? !partition.nil? && !partition.empty? && !service.nil? && !service.empty? && !resource.nil? && !resource.empty? end |