Repository: boto/botocore
Pull request #2831 (2022-12-12 15:13:25)

Update ARN delimiter parsing in endpoint provider
This addresses a bug for `aws_parse_arn` in `endpoint_provider.RuleSetStandardLibrary`. Currently the `resourceId` portion of a parsed ARN was only thought to either have a `/` or `:` as a delimiter. However, in services such as `kinesis`, they can have both.

Current Behavior
`arn:aws:kinesis:1234567890:us-east-1:thing/foo:bar`  -> `{...'resourceId': ['thing/foo', 'bar']}`

New Behavior
`arn:aws:kinesis:1234567890:us-east-1:thing/foo:bar`  -> `{...'resourceId': ['thing', 'foo', 'bar']}`


codecov-commenter: # [Codecov](https://codecov.io/gh/boto/botocore/pull/2831?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=boto) Report
Base: **93.53**% // Head: **93.53**% // No change to project coverage :thumbsup:
> Coverage data is based on head [(`21cb317`)](https://codecov.io/gh/boto/botocore/pull/2831?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=boto) compared to base [(`9b6f5ad`)](https://codecov.io/gh/boto/botocore/commit/9b6f5ad3f61eb875d70333847cc06abf22c54c80?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=boto).
> Patch coverage: 100.00% of modified lines in pull request are covered.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff            @@
##           develop    #2831   +/-   ##
========================================
  Coverage    93.53%   93.53%           
========================================
  Files           63       63           
  Lines        13382    13382           
========================================
  Hits         12517    12517           
  Misses         865      865           
```


| [Impacted Files](https://codecov.io/gh/boto/botocore/pull/2831?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=boto) | Coverage Δ | |
|---|---|---|
| [botocore/endpoint\_provider.py](https://codecov.io/gh/boto/botocore/pull/2831/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=boto#diff-Ym90b2NvcmUvZW5kcG9pbnRfcHJvdmlkZXIucHk=) | `99.35% <100.00%> (ø)` | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=boto). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=boto)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/boto/botocore/pull/2831?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=boto).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=boto).


Patch:
diff --git a/.changes/next-release/bugfix-Endpointprovider-32427.json b/.changes/next-release/bugfix-Endpointprovider-32427.json
new file mode 100644
index 000000000..a75daf298
--- /dev/null
+++ b/.changes/next-release/bugfix-Endpointprovider-32427.json
@@ -0,0 +1,5 @@
+{
+  "type": "bugfix",
+  "category": "Endpoint provider",
+  "description": "Updates ARN parsing ``resourceId`` delimiters"
+}
diff --git a/botocore/endpoint_provider.py b/botocore/endpoint_provider.py
index f90eb94db..c31981701 100644
--- a/botocore/endpoint_provider.py
+++ b/botocore/endpoint_provider.py
@@ -47,6 +47,7 @@ GET_ATTR_RE = re.compile(r"(\w+)\[(\d+)\]")
 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()
@@ -236,8 +237,7 @@ class RuleSetStandardLibrary:
         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
 


Test patch:
diff --git a/tests/unit/test_endpoint_provider.py b/tests/unit/test_endpoint_provider.py
index bbcbade06..1009c47cb 100644
--- a/tests/unit/test_endpoint_provider.py
+++ b/tests/unit/test_endpoint_provider.py
@@ -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