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
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.
37 38 39 40 41 42 43 |
# File 'lib/aws-sdk-core/arn.rb', line 37 def initialize( = {}) @partition = [:partition] @service = [:service] @region = [:region] @account_id = [:account_id] @resource = [:resource] end |
Instance Attribute Details
#account_id ⇒ String (readonly)
55 56 57 |
# File 'lib/aws-sdk-core/arn.rb', line 55 def account_id @account_id end |
#partition ⇒ String (readonly)
46 47 48 |
# File 'lib/aws-sdk-core/arn.rb', line 46 def partition @partition end |
#region ⇒ String (readonly)
52 53 54 |
# File 'lib/aws-sdk-core/arn.rb', line 52 def region @region end |
#resource ⇒ String (readonly)
58 59 60 |
# File 'lib/aws-sdk-core/arn.rb', line 58 def resource @resource end |
#service ⇒ String (readonly)
49 50 51 |
# File 'lib/aws-sdk-core/arn.rb', line 49 def service @service end |
Instance Method Details
#as_json(_options = nil) ⇒ Hash
Return the ARN as JSON
93 94 95 96 97 98 99 100 101 |
# File 'lib/aws-sdk-core/arn.rb', line 93 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
80 81 82 83 84 85 86 87 88 |
# File 'lib/aws-sdk-core/arn.rb', line 80 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
73 74 75 |
# File 'lib/aws-sdk-core/arn.rb', line 73 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.
64 65 66 67 68 |
# File 'lib/aws-sdk-core/arn.rb', line 64 def valid? !partition.nil? && !partition.empty? && !service.nil? && !service.empty? && !resource.nil? && !resource.empty? end |