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 parsing s3 accesspoint url #1743

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 8 additions & 0 deletions fsspec/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,16 @@ def test_infer_options():
# - The bucket is included in path
for protocol in ["s3", "s3a", "gcs", "gs"]:
options = infer_storage_options(f"{protocol}://Bucket-name.com/test.csv")
assert options["host"] == "Bucket-name.com"
assert options["path"] == "Bucket-name.com/test.csv"

for protocol in ["s3", "s3a"]:
options = infer_storage_options(
f"{protocol}://arn:aws:s3:us-west-2:1234:accesspoint/abc/test.csv"
)
assert options["host"] == "arn:aws:s3:us-west-2:1234:accesspoint"
assert options["path"] == "arn:aws:s3:us-west-2:1234:accesspoint/abc/test.csv"

with pytest.raises(KeyError):
infer_storage_options("file:///bucket/file.csv", {"path": "collide"})
with pytest.raises(KeyError):
Expand Down
13 changes: 9 additions & 4 deletions fsspec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,17 @@ def infer_storage_options(
# https://github.com/dask/dask/issues/1417
options["host"] = parsed_path.netloc.rsplit("@", 1)[-1].rsplit(":", 1)[0]

if protocol in ("s3", "s3a") and parsed_path.netloc.endswith(":accesspoint"):
# When receiving a s3 accesspoint url like s3://arn:aws:s3:us-west-2:1234:accesspoint/abc
# the :accesspoint suffix would fail the port parsing with a ValueError complaining the port is not an integer
# Ignore the port setting and keep the :accesspoint suffix in the options["host"]
options["host"] = parsed_path.netloc.rsplit("@", 1)[-1]
else:
if parsed_path.port:
options["port"] = parsed_path.port

if protocol in ("s3", "s3a", "gcs", "gs"):
options["path"] = options["host"] + options["path"]
else:
options["host"] = options["host"]
if parsed_path.port:
options["port"] = parsed_path.port
if parsed_path.username:
options["username"] = parsed_path.username
if parsed_path.password:
Expand Down
Loading