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

Update ARN delimiter parsing in endpoint provider #2831

Merged
merged 2 commits into from
Dec 12, 2022

Conversation

dlm6693
Copy link
Contributor

@dlm6693 dlm6693 commented Dec 12, 2022

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']}

@dlm6693 dlm6693 force-pushed the arn-delimiter-endpoints branch from b4fc59f to 21cb317 Compare December 12, 2022 15:15
@codecov-commenter
Copy link

Codecov Report

Base: 93.53% // Head: 93.53% // No change to project coverage 👍

Coverage data is based on head (21cb317) compared to base (9b6f5ad).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2831   +/-   ##
========================================
  Coverage    93.53%   93.53%           
========================================
  Files           63       63           
  Lines        13382    13382           
========================================
  Hits         12517    12517           
  Misses         865      865           
Impacted Files Coverage Δ
botocore/endpoint_provider.py 99.35% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@jonathan343 jonathan343 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@dlm6693 dlm6693 merged commit dddd199 into boto:develop Dec 12, 2022
@dlm6693 dlm6693 deleted the arn-delimiter-endpoints branch December 12, 2022 18:06
Copy link
Contributor

@jonemo jonemo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed elsewhere already, using the regex in this case is approximately 3x slower in my tests than the non-regex solution:

"abc:def/ghi".replace(":", "/"). split("/")
['abc', 'def', 'ghi']

If you decide to stick with the regex implementation, a nit: ARN_DELIMITER_RE would be more precise if called ARN_RESOURCE_DELIMITER_RE because "ARN delimiter" usually refers to the : that separate the top-level parts of the ARN.

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if there is a difference, but why not use split on the compiled object?

Suggested change
arn_dict["resourceId"] = re.split(ARN_DELIMITER_RE, resource)
arn_dict["resourceId"] = ARN_DELIMITER_RE.split(resource)

@dlm6693
Copy link
Contributor Author

dlm6693 commented Dec 12, 2022

@jonemo thanks for the feedback. I did some testing of my own and I do also see that the standard string splitting in Python is much faster than using regex. We needed to get this merged before today's release otherwise I would've waited for more feedback, but I'll put up a followup PR that we can merge later today or tomorrow.

aws-sdk-python-automation added a commit that referenced this pull request Dec 12, 2022
* release-1.29.28:
  Bumping version to 1.29.28
  Update to latest partitions and endpoints
  Update to latest models
  Update ARN delimiter parsing in endpoint provider (#2831)
kyleknap added a commit to kyleknap/aws-cli that referenced this pull request Dec 13, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants