Skip to content
Merged
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
1 change: 1 addition & 0 deletions cdk/constructs/DpsStacItemGenerator/runtime/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies = [
"pydantic>=2.11.0",
"pystac[validation]>=1.13.0",
"stac-pydantic>=3.2.0",
"python-slugify==8.0.4",
]

[dependency-groups]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pystac import Link
from pystac.stac_io import DefaultStacIO, StacIO
from stac_pydantic.item import Item
from slugify import slugify

logger = logging.getLogger()
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -94,7 +95,7 @@ def get_stac_items(catalog_json_key: str) -> Generator[Item, Any, Any]:
f"could not locate the .met.json file with the DPS job outputs in {job_output_prefix}"
)

collection_id = COLLECTION_ID_FORMAT.format(**job_metadata)
collection_id = slugify(COLLECTION_ID_FORMAT.format(**job_metadata), regex_pattern=r'[/\?#%& ]+')

catalog = pystac.Catalog.from_file(catalog_json_key)
catalog.make_all_asset_hrefs_absolute()
Expand Down
22 changes: 22 additions & 0 deletions cdk/constructs/DpsStacItemGenerator/runtime/tests/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,25 @@ def test_get_stac_items_invalid_catalog_json(self, mock_job_metadata):
Exception, match="Failed to parse catalog.json: invalid format"
):
list(get_stac_items(catalog_s3_key))

def test_santitize_collection_id(self, mock_catalog, mock_job_metadata):
"""Test that collection ID is sanitized correctly."""
catalog_s3_key = "s3://test-bucket/2023/01/15/10/30/45/123456/catalog.json"
mock_job_metadata["username"] = "user/name"
mock_job_metadata["algorithm_name"] = "algo?name"
expected_collection_id = "user-name__algo-name__0.1__test"

with (
patch(
"dps_stac_item_generator.item.pystac.Catalog.from_file",
return_value=mock_catalog,
),
patch(
"dps_stac_item_generator.item.load_met_json",
return_value=mock_job_metadata,
),
):
items = list(get_stac_items(catalog_s3_key))

for item in items:
assert item.collection == expected_collection_id
25 changes: 24 additions & 1 deletion cdk/constructs/DpsStacItemGenerator/runtime/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.