Skip to content

Commit e4e2747

Browse files
committed
Configure stock s3fs for anonymous access to handle public DRS S3 URLs, and remove the now-unused _download_s3_file bypass function
1 parent d40e20f commit e4e2747

File tree

2 files changed

+8
-61
lines changed

2 files changed

+8
-61
lines changed

lib/galaxy/files/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,14 @@ def _ensure_loaded(plugin_type):
162162
_ensure_loaded("base64")
163163
_ensure_loaded("drs")
164164
_ensure_loaded("remoteZip")
165-
# Do we actually want to do this here, if we're doing drs+s3fs?
166-
_ensure_loaded("s3fs")
165+
# Load s3fs with anonymous access for public DRS S3 URLs
166+
s3fs_configured = False
167+
for file_source in file_sources:
168+
if file_source.plugin_type == "s3fs":
169+
s3fs_configured = True
170+
break
171+
if not s3fs_configured:
172+
stock_file_source_conf_dict.append({"type": "s3fs", "id": "stock_s3fs", "anon": True})
167173

168174
if file_sources_config.ftp_upload_dir is not None:
169175
_ensure_loaded("gxftp")

lib/galaxy/files/sources/util.py

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -115,65 +115,6 @@ def _get_access_info(obj_url: str, access_method: dict, headers: Optional[dict]
115115
return url, headers_as_dict
116116

117117

118-
def _download_s3_file(s3_url: str, target_path: StrPath, headers: Optional[dict] = None) -> None:
119-
"""Download file from S3 URL directly using s3fs or requests (for signed URLs)."""
120-
try:
121-
# If the URL has query parameters (signed URL), use requests directly
122-
if "?" in s3_url and ("X-Amz-Algorithm" in s3_url or "Signature" in s3_url):
123-
log.debug(f"Using requests for signed S3 URL")
124-
response = requests.get(s3_url, headers=headers or {}, timeout=DEFAULT_SOCKET_TIMEOUT, stream=True)
125-
response.raise_for_status()
126-
127-
with open(target_path, "wb") as f:
128-
for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
129-
f.write(chunk)
130-
return
131-
132-
# For raw S3 URLs, try s3fs with different access patterns
133-
log.debug(f"Using s3fs for S3 URL: {s3_url}")
134-
import s3fs
135-
136-
s3_path = s3_url[5:] # Remove 's3://' prefix
137-
138-
# Try different S3 access methods in order of preference
139-
access_methods = [
140-
("anonymous", lambda: s3fs.S3FileSystem(anon=True)),
141-
("authenticated", lambda: s3fs.S3FileSystem()),
142-
("requester_pays", lambda: s3fs.S3FileSystem(requester_pays=True)),
143-
]
144-
145-
last_error = None
146-
for method_name, fs_factory in access_methods:
147-
try:
148-
fs = fs_factory()
149-
with fs.open(s3_path, "rb") as s3_file:
150-
with open(target_path, "wb") as local_file:
151-
while True:
152-
chunk = s3_file.read(CHUNK_SIZE)
153-
if not chunk:
154-
break
155-
local_file.write(chunk)
156-
log.debug(f"S3 download successful using {method_name} access")
157-
return
158-
except Exception as e:
159-
log.debug(f"S3 {method_name} access failed: {e}")
160-
last_error = e
161-
continue
162-
163-
# If all methods failed, raise the last error
164-
if last_error:
165-
raise last_error
166-
167-
except ImportError as e:
168-
raise ImportError("s3fs package is required for S3 URL support") from e
169-
except requests.exceptions.RequestException as e:
170-
log.debug(f"S3 HTTP download failed: {e}")
171-
raise
172-
except Exception as e:
173-
log.debug(f"S3 download failed: {e}")
174-
raise
175-
176-
177118
class CompactIdentifierResolver:
178119
_instance: Optional["CompactIdentifierResolver"] = None
179120
_initialized: bool = False

0 commit comments

Comments
 (0)