Skip to content
This repository was archived by the owner on May 16, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions arnparse/arnparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def arnparse(arn_str):
raise MalformedArnError(arn_str)

elements = arn_str.split(':', 5)

if "volume/vol-" in arn_str:
elements = elements[:2] + ["volume"] + elements[2:]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you take a look at the actual list of AWS services. volume is not one of them. I think we should either specify ec2 as the service (which is more accurate), or we could leave it empty to represent the fact that it's not part of the ARN. What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ec2 might be miss-leading. though it is the service, it can often be referred as a VM.
ec2 contains multiple services in aws.

Maybe the best name would be EBS?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to paste the link to the service page: https://docs.aws.amazon.com/general/latest/gr/rande.html. You can see that neither volume nor ebs is an actual AWS service. Per experience, AWS almost never reference anything by the term VM, so I wouldn't go with that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it. thanks.
How would you suggest supporting volume arn parsing without loosing the ability to categorize the type?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you take a look at the CloudFormation definition of a Volume. It's categorized as being part of EC2. But I'm really curious as to where did you get this ARN from? I think I never saw a volume ARN before. I honestly thought they didn't exist.

Copy link
Contributor

@laurrentt laurrentt Oct 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to this page https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-policy-structure.html#EC2_ARN_Format, the volume ARN does, in fact, include the ec2 service name: arn:aws:ec2:region:account:volume/volume-id.

2019-10-21 at 1 49 PM


service = elements[2]
resource = elements[5]

Expand Down
11 changes: 11 additions & 0 deletions tests/test_arnparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ def test__arnparse__resource_with_multiple_slashes():
assert arn.resource_type == 'trigger'
assert arn.resource == 'example61b3df36bff1dafaf1aa304b0ef1a975/alert/example8780e9ca227f98dae37665c3fd22b585'

def test__arnparse__resource_with_no_service():
arn_str = 'arn:aws:us-east-1:123456789012:volume/vol-00000000000000001'

arn = arnparse(arn_str)

assert arn.partition == 'aws'
assert arn.service == 'volume'
assert arn.region == 'us-east-1'
assert arn.account_id == '123456789012'
assert arn.resource_type == 'volume'
assert arn.resource == 'vol-00000000000000001'

def test__arnparse__no_region__no_acount_id():
arn_str = 'arn:aws:s3:::my_corporate_bucket'
Expand Down