Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix s3 op router following botocore 1.31.2 #8672

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

Merged
merged 6 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion localstack/aws/forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,11 @@ def create_aws_request_context(
if auth_path := request_dict.get("auth_path"):
# botocore >= 1.28 might modify the url path of the request dict (specifically for S3).
# It will then set the original url path as "auth_path". If the auth_path is set, we reset the url_path.
# Since botocore 1.31.2, botocore will strip the query from the `authPart`
# We need to add it back from `requestUri` field
# Afterwards the request needs to be prepared again.
request_dict["url_path"] = auth_path
path, sep, query = request_dict["url_path"].partition("?")
request_dict["url_path"] = f"{auth_path}{sep}{query}"
prepare_request_dict(
request_dict,
endpoint_url=endpoint_url,
Expand Down
8 changes: 6 additions & 2 deletions localstack/aws/protocol/op_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ class _HttpOperation(NamedTuple):
@staticmethod
def from_operation(op: OperationModel) -> "_HttpOperation":
# botocore >= 1.28 might modify the internal model (specifically for S3).
# It will modify the request URI and set the original value at "authPath".
# It will modify the request URI to strip the bucket name from the path and set the original value at
# "authPath".
# Since botocore 1.31.2, botocore will strip the query from the `authPart`
# We need to add it back from `requestUri` field
# Use authPath if set, otherwise use the regular requestUri.
if auth_path := op.http.get("authPath"):
uri = auth_path.rstrip("/")
path, sep, query = op.http.get("requestUri", "").partition("?")
uri = f"{auth_path.rstrip('/')}{sep}{query}"
else:
uri = op.http.get("requestUri")

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ runtime =
awscrt>=0.13.14
boto>=2.49.0
boto3>=1.26.121
botocore>=1.29.133
botocore>=1.31.2
cbor2>=5.2.0
crontab>=0.22.6
dnslib>=0.9.10
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/aws/protocol/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,11 @@ def _botocore_parser_integration_test(

# botocore >= 1.28 might modify the url path of the request dict (specifically for S3).
# It will then set the original url path as "auth_path". If the auth_path is set, we reset the url_path.
# Since botocore 1.31.2, botocore will strip the query from the `authPart`
# We need to add it back from `requestUri` field
if auth_path := serialized_request.get("auth_path"):
serialized_request["url_path"] = auth_path
path, sep, query = serialized_request["url_path"].partition("?")
serialized_request["url_path"] = f"{auth_path}{sep}{query}"

prepare_request_dict(serialized_request, "")
split_url = urlsplit(serialized_request.get("url"))
Expand Down