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

Fix S3 URL Handler for good #19285

Merged
merged 3 commits into from
Jun 10, 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
3 changes: 3 additions & 0 deletions src/python/pants/backend/url_handlers/s3/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import sys
from http.client import HTTPMessage
from http.server import BaseHTTPRequestHandler
from types import SimpleNamespace

Expand Down Expand Up @@ -47,6 +48,8 @@ def do_patching(expected_url):
fake_session = object()
fake_creds = SimpleNamespace(access_key="ACCESS", secret_key="SECRET", token=None)
botocore.session = SimpleNamespace(get_session=lambda: fake_session)
# NB: HTTPHeaders is just a simple subclass of HTTPMessage
botocore.compat = SimpleNamespace(HTTPHeaders=HTTPMessage)

def fake_resolver_creator(session):
assert session is fake_session
Expand Down
8 changes: 2 additions & 6 deletions src/python/pants/backend/url_handlers/s3/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class S3DownloadFile:

@rule
async def download_from_s3(request: S3DownloadFile, aws_credentials: AWSCredentials) -> Digest:
from botocore import auth, exceptions # pants: no-infer-dep
from botocore import auth, compat, exceptions # pants: no-infer-dep

# NB: The URL for auth is expected to be in path-style
path_style_url = "https://s3"
Expand All @@ -74,11 +74,7 @@ async def download_from_s3(request: S3DownloadFile, aws_credentials: AWSCredenti
if request.query:
path_style_url += f"?{request.query}"

headers: dict[str, str] = {}
if aws_credentials.creds.token:
# Workaround https://github.com/boto/botocore/pull/2948
headers["X-Amz-Security-Token"] = ""

headers = compat.HTTPHeaders()
http_request = SimpleNamespace(
url=path_style_url,
headers=headers,
Expand Down