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

Workaround botocore bug in S3 URL Handler backend #19056

Merged
merged 7 commits into from
May 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def do_patching(expected_url):
botocore = SimpleNamespace()
botocore.exceptions = SimpleNamespace(NoCredentialsError=Exception)
fake_session = object()
fake_creds = SimpleNamespace(access_key="ACCESS", secret_key="SECRET")
fake_creds = SimpleNamespace(access_key="ACCESS", secret_key="SECRET", token=None)
botocore.session = SimpleNamespace(get_session=lambda: fake_session)

def fake_resolver_creator(session):
Expand Down
9 changes: 8 additions & 1 deletion src/python/pants/backend/url_handlers/s3/register.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from __future__ import annotations

import logging
from dataclasses import dataclass
from types import SimpleNamespace
Expand Down Expand Up @@ -72,9 +74,14 @@ 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"] = ""

http_request = SimpleNamespace(
url=path_style_url,
headers={},
headers=headers,
method="GET",
auth_path=None,
)
Expand Down