Skip to content

Commit

Permalink
Add envvar for OscZarr S3 endpoint.
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Barrachina Civera <xbarrachina@arfima.com>
  • Loading branch information
xbarra committed Aug 16, 2024
1 parent 5e37861 commit a80a584
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/hazard/sources/osc_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

class OscZarr(ReadWriteDataArray):
__access_key = "OSC_S3_ACCESS_KEY_DEV"
__endpoint_url = "OSC_S3_ENDPOINT_DEV"
__secret_key = "OSC_S3_SECRET_KEY_DEV"
__token = "OSC_S3_TOKEN_DEV"

Expand All @@ -42,14 +43,15 @@ def __init__(
if s3 is None:
# zarr_utilities.load_dotenv() # to load environment variables
access_key = os.environ.get(self.__access_key, None)
endpoint_url = os.environ.get(self.__endpoint_url, None)
secret_key = os.environ.get(self.__secret_key, None)
token = os.environ.get(self.__token, None)
if token:
s3 = s3fs.S3FileSystem(
key=access_key, secret=secret_key, token=token
)
else:
s3 = s3fs.S3FileSystem(key=access_key, secret=secret_key)
s3 = s3fs.S3FileSystem(
key=access_key,
secret=secret_key,
token=token,
endpoint_url=endpoint_url,
)

group_path = str(PurePosixPath(bucket, prefix, "hazard.zarr"))
store = s3fs.S3Map(root=group_path, s3=s3, check=False)
Expand Down

0 comments on commit a80a584

Please sign in to comment.