Skip to content

Commit

Permalink
Issue #16 Better way to configure Uploader class
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanKJSchreurs committed Feb 27, 2024
1 parent c82f4db commit d476cf3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions stacbuilder/commandapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -389,15 +390,16 @@ 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.
"""
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)


Expand Down
10 changes: 5 additions & 5 deletions stacbuilder/stacapi/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d476cf3

Please sign in to comment.