diff --git a/stacbuilder/commandapi.py b/stacbuilder/commandapi.py index f879998..d5a834e 100644 --- a/stacbuilder/commandapi.py +++ b/stacbuilder/commandapi.py @@ -30,6 +30,7 @@ from stacbuilder.metadata import AssetMetadata from stacbuilder.terracatalog import HRLVPPMetadataCollector, CollectionConfigBuilder from stacbuilder.stacapi.upload import Uploader +from stacbuilder.stacapi.config import Settings def build_collection( @@ -389,7 +390,7 @@ def _check_tcc_collection_id(collection_id: Optional[str]) -> str: return collection_id -def upload_to_stac_api(collection_path: Path) -> None: +def upload_to_stac_api(collection_path: Path, settings: Settings) -> None: """Upload a collection to the STAC API. TODO: The STAC API has to be configured via a settings file. @@ -397,7 +398,8 @@ def upload_to_stac_api(collection_path: Path) -> None: if isinstance(collection_path, str): collection_path = Path(collection_path) - uploader = Uploader.from_settings() + uploader = Uploader.from_settings(settings) + uploader._collections_endpoint.get_all() uploader.upload_collection_and_items(collection_path) diff --git a/stacbuilder/stacapi/upload.py b/stacbuilder/stacapi/upload.py index ed9d679..f6c3c1d 100644 --- a/stacbuilder/stacapi/upload.py +++ b/stacbuilder/stacapi/upload.py @@ -19,15 +19,15 @@ def __init__(self, collections_ep: CollectionsEndpoint, items_ep: ItemsEndpoint) self._collections_endpoint = collections_ep self._items_endpoint = items_ep - @staticmethod - def from_settings(settings: Settings) -> "Uploader": + @classmethod + def from_settings(cls, settings: Settings) -> "Uploader": auth = get_auth(settings.auth) - return Uploader( + return cls.setup( stac_api_url=settings.stac_api_url, auth=auth, collection_auth_info=settings.collection_auth_info ) - @classmethod - def setup(cls, stac_api_url: URL, auth: AuthBase | None, collection_auth_info: dict | None = None) -> "Uploader": + @staticmethod + def setup(stac_api_url: URL, auth: AuthBase | None, collection_auth_info: dict | None = None) -> "Uploader": collections_endpoint = CollectionsEndpoint( stac_api_url=stac_api_url, auth=auth,