Skip to content

Commit

Permalink
Fix ARN parsing behavior for endpoint provider
Browse files Browse the repository at this point in the history
Specifically, the previous implementation did not handle ARNs that
use both colon and slashes as delimeters. This is a port from the
original implementation across the following PRs:

* boto/botocore#2831
* boto/botocore#2834
  • Loading branch information
kyleknap committed Dec 13, 2022
1 parent af5414d commit 8060549
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-Endpointprovider-32427.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "Endpoint provider",
"description": "Updates ARN parsing ``resourceId`` delimiters"
}
3 changes: 1 addition & 2 deletions awscli/botocore/endpoint_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ def aws_parse_arn(self, value):
arn_dict["accountId"] = arn_dict.pop("account")

resource = arn_dict.pop("resource")
delimiter = ":" if ":" in resource else "/"
arn_dict["resourceId"] = resource.split(delimiter)
arn_dict["resourceId"] = resource.replace(":", "/").split("/")

return arn_dict

Expand Down
41 changes: 41 additions & 0 deletions tests/unit/botocore/test_endpoint_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,47 @@ def test_invalid_arn_returns_none(rule_lib):
assert rule_lib.aws_parse_arn("arn:aws:this-is-not-an-arn:foo") is None


@pytest.mark.parametrize(
"arn, expected_resource_id",
[
(
"arn:aws:s3:::myBucket/key",
{
"partition": "aws",
"service": "s3",
"region": "",
"accountId": "",
"resourceId": ["myBucket", "key"],
},
),
(
"arn:aws:kinesis:us-east-1:1234567890:stream/mystream:foo",
{
"partition": "aws",
"service": "kinesis",
"region": "us-east-1",
"accountId": "1234567890",
"resourceId": ["stream", "mystream", "foo"],
},
),
(
"arn:aws:s3:::myBucket",
{
"partition": "aws",
"service": "s3",
"region": "",
"accountId": "",
"region": "",
"resourceId": ["myBucket"],
},
),
],
)
def test_parse_arn_delimiters(rule_lib, arn, expected_resource_id):
parsed_arn = rule_lib.aws_parse_arn(arn)
assert parsed_arn == expected_resource_id


def test_uri_encode_none_returns_none(rule_lib):
assert rule_lib.uri_encode(None) is None

Expand Down

0 comments on commit 8060549

Please sign in to comment.