Skip to content

Commit

Permalink
Merge pull request #67 from digitalearthpacific/add-option-stac-https…
Browse files Browse the repository at this point in the history
…-hrefs

Add option to make stac hrefs HTTPS instead of S3 URIs
  • Loading branch information
jessjaco authored Oct 9, 2024
2 parents 88f0c0c + fd4e758 commit e40fd98
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion dep_tools/stac_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ def __init__(
itempath: DepItemPath,
remote: bool = True,
collection_url_root: str = "https://stac.staging.digitalearthpacific.org/collections",
make_hrefs_https: bool = False,
**kwargs,
):
self._itempath = itempath
self._remote = remote
self._collection_url_root = collection_url_root
self._make_hrefs_https = make_hrefs_https
self._kwargs = kwargs

def process(
Expand All @@ -39,6 +41,7 @@ def process(
data=data,
remote=self._remote,
collection_url_root=self._collection_url_root,
make_hrefs_https=self._make_hrefs_https,
**self._kwargs,
)

Expand All @@ -49,6 +52,7 @@ def get_stac_item(
data: DataArray | Dataset,
remote: bool = True,
collection_url_root: str = "https://stac.staging.digitalearthpacific.org/collections",
make_hrefs_https: bool = False,
**kwargs,
) -> Item | str:
prefix = Path("./")
Expand All @@ -58,7 +62,14 @@ def get_stac_item(
# Or, isinstance(itempath, S3ItemPath)
if hasattr(itempath, "bucket"):
# Writing to S3
prefix = URL(f"s3://{getattr(itempath,'bucket')}")
if make_hrefs_https:
# E.g., https://dep-public-prod.s3.us-west-2.amazonaws.com/
prefix = URL(
f"https://{getattr(itempath, 'bucket')}.s3/us-west-2.amazonaws.com"
)
else:
# E.g., s3://dep-public-prod/
prefix = URL(f"s3://{getattr(itempath, 'bucket')}")
else:
# Default to Azure
prefix = URL("https://deppcpublicstorage.blob.core.windows.net/output")
Expand Down

0 comments on commit e40fd98

Please sign in to comment.