Skip to content

Commit

Permalink
Update ARN delimiter parsing in endpoint provider (#2831)
Browse files Browse the repository at this point in the history
* support : and / separators for arn resourceId

* changelog
  • Loading branch information
dlm6693 authored Dec 12, 2022
1 parent 9b6f5ad commit dddd199
Show file tree
Hide file tree
Showing 3 changed files with 48 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"
}
4 changes: 2 additions & 2 deletions botocore/endpoint_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
VALID_HOST_LABEL_RE = re.compile(
r"^(?!-)[a-zA-Z\d-]{1,63}(?<!-)$",
)
ARN_DELIMITER_RE = re.compile(r"/|:")
CACHE_SIZE = 100
ARN_PARSER = ArnParser()
STRING_FORMATTER = Formatter()
Expand Down Expand Up @@ -236,8 +237,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"] = re.split(ARN_DELIMITER_RE, resource)

return arn_dict

Expand Down
41 changes: 41 additions & 0 deletions tests/unit/test_endpoint_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,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 dddd199

Please sign in to comment.