Skip to content

Commit

Permalink
support s3fs for anonymous creds
Browse files Browse the repository at this point in the history
  • Loading branch information
jreadey committed Apr 26, 2024
1 parent 61450cb commit 7c0db10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/read_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def load_file():
print("running command:", " ".join(run_cmd))
result = subprocess.run(run_cmd)
if result.returncode != 0:
print(f"unable able to hsload {s3_uri}, error: {run_cmd.returncode}")
print(f"unable able to hsload {s3_uri}, error: {result.returncode}")
sys.exit(1)
print("hsload complete")
# now we should be able to open the domain
Expand Down
14 changes: 12 additions & 2 deletions h5pyd/_apps/hsload.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,24 @@ def main():
sys.exit(1)

if not s3:
kwargs = {"use_ssl": False}
key = os.environ.get("AWS_ACCESS_KEY_ID")
secret = os.environ.get("AWS_SECRET_ACCESS_KEY")
aws_s3_gateway = os.environ.get("AWS_GATEWAY")

if not key or not secret:
kwargs["anon"] = True
else:
kwargs["key"] = key
kwargs["secret"] = secret

client_kwargs = {}
aws_s3_gateway = os.environ.get("AWS_GATEWAY")
if aws_s3_gateway:
client_kwargs["endpoint_url"] = aws_s3_gateway
if client_kwargs:
kwargs["client_kwargs"] = client_kwargs

s3 = s3fs.S3FileSystem(use_ssl=False, key=key, secret=secret, client_kwargs=client_kwargs)
s3 = s3fs.S3FileSystem(**kwargs)
try:
fin = h5py.File(s3.open(src_file, "rb"), moe="r")
except IOError as ioe:
Expand Down

0 comments on commit 7c0db10

Please sign in to comment.