Skip to content

Commit

Permalink
Do not remove account and region from non-bucket s3 ARNs
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-k committed Jun 15, 2021
1 parent aba4018 commit 2cc5043
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
7 changes: 5 additions & 2 deletions awacs/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ def __init__(
else:
aws_partition = "aws"

regionless = ["iam", "s3"]
if service in regionless:
if service == "iam":
region = ""
elif service == "s3" and not resource.startswith(
("accesspoint/", "job/", "storage-lens/")
):
region = ""

self.data = "arn:%s:%s:%s:%s:%s" % (
Expand Down
8 changes: 6 additions & 2 deletions awacs/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ def __init__(self, action: str = None) -> None:

class ARN(BaseARN):
def __init__(self, resource: str = "", region: str = "", account: str = "") -> None:
# account is empty for S3
super().__init__(service=prefix, resource=resource, region=region, account="")
# account is empty for S3 buckets
if not resource.startswith(("accesspoint/", "job/", "storage-lens/")):
account = ""
super().__init__(
service=prefix, resource=resource, region=region, account=account
)


AbortMultipartUpload = Action("AbortMultipartUpload")
Expand Down
8 changes: 6 additions & 2 deletions scrape/scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ def __init__(self, action: str = None) -> None:
class ARN(BaseARN):
def __init__(self, resource: str = "", region: str = "", account: str = "") -> None:
# account is empty for S3
super().__init__(service=prefix, resource=resource, region=region, account="")
# account is empty for S3 buckets
if not resource.startswith(("accesspoint/", "job/", "storage-lens/")):
account = ""
super().__init__(
service=prefix, resource=resource, region=region, account=account
)
"""

BASEDIR = "awacs"
Expand Down
11 changes: 11 additions & 0 deletions tests/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ def test_cn(self):
def test_gov(self):
arn = ARN("bucket/key", "us-gov-west-1", "account")
self.assertEqual(arn.JSONrepr(), "arn:aws-us-gov:s3:::bucket/key")

def test_non_bucket_arns(self):
for resource in [
"accesspoint/my-access-point",
"job/job-id",
"storage-lens/config-id",
]:
arn = ARN(resource, "us-east-1", "111122223333")
self.assertEqual(
arn.JSONrepr(), f"arn:aws:s3:us-east-1:111122223333:{resource}"
)

0 comments on commit 2cc5043

Please sign in to comment.