Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS Service matching regex ARN expand matches #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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: 3 additions & 1 deletion policyuniverse/arn.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def __init__(self, input):
self._from_account_number(input)
return

aws_service_match = re.search(r"^(([^.]+)(.[^.]+)?)\.amazon(aws)?\.com$", input)
aws_service_match = re.search(
r"^(([^.])((.*)[^.])?)\.amazon(aws)?\.com$", input
)
if aws_service_match:
self._from_aws_service(input, aws_service_match.group(1))
return
Expand Down
19 changes: 19 additions & 0 deletions policyuniverse/tests/test_arn.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@
class ARNTestCase(unittest.TestCase):
def test_from_arn(self):
proper_arns = [
"ec2.amazonaws.com",
"events.amazonaws.com",
"cloudtrail.amazonaws.com",
"stacksets.cloudformation.amazonaws.com",
"aws-artifact-account-sync.amazonaws.com",
"member.org.stacksets.cloudformation.amazonaws.com",
"arn:aws:iam::012345678910:root",
"arn:aws:iam::012345678910:role/SomeTestRoleForTesting",
"arn:aws:iam::012345678910:instance-profile/SomeTestInstanceProfileForTesting",
Expand Down Expand Up @@ -103,3 +107,18 @@ def test_from_account_number(self):
arn_obj = ARN(accnt)

self.assertTrue(arn_obj.error)

def test_aws_service_arn_tech(self):
proper_arn_techs = {
"ec2.amazonaws.com": "ec2",
"events.amazonaws.com": "events",
"cloudtrail.amazonaws.com": "cloudtrail",
"stacksets.cloudformation.amazonaws.com": "stacksets.cloudformation",
"aws-artifact-account-sync.amazonaws.com": "aws-artifact-account-sync",
"member.org.stacksets.cloudformation.amazonaws.com": "member.org.stacksets.cloudformation",
}

for arn, tech in proper_arn_techs.items():
arn_obj = ARN(arn)
self.assertFalse(arn_obj.error)
self.assertTrue(arn_obj.tech == tech)