Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ingestor-api): stricter collections endpoints #36

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
11 changes: 4 additions & 7 deletions lib/ingestor-api/runtime/src/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ def ingest(collection: StacCollection):
does necessary preprocessing,
and loads into the PgSTAC collection table
"""
try:
creds = get_db_credentials(os.environ["DB_SECRET_ARN"])
with PgstacDB(dsn=creds.dsn_string, debug=True) as db:
loader = Loader(db=db)
loader.load_collection(file=collection, insert_mode=Methods.upsert)
except Exception as e:
print(f"Encountered failure loading collection into pgSTAC: {e}")
creds = get_db_credentials(os.environ["DB_SECRET_ARN"])
with PgstacDB(dsn=creds.dsn_string, debug=True) as db:
loader = Loader(db=db)
loader.load_collection(file=collection, insert_mode=Methods.upsert)


def delete(collection_id: str):
Expand Down
25 changes: 8 additions & 17 deletions lib/ingestor-api/runtime/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,24 @@ def cancel_ingestion(
@app.post(
"/collections",
tags=["Collection"],
status_code=201,
dependencies=[Depends(dependencies.get_username)],
status_code=201,
)
def publish_collection(collection: schemas.StacCollection):
# pgstac create collection
try:
collection_loader.ingest(collection)
return {f"Successfully published: {collection.id}"}
except Exception as e:
raise HTTPException(
status_code=400,
detail=(f"Unable to publish collection: {e}"),
)
def publish_collection(
collection: schemas.StacCollection
) -> schemas.StacCollection:
collection_loader.ingest(collection)
return collection


@app.delete(
"/collections/{collection_id}",
tags=["Collection"],
dependencies=[Depends(dependencies.get_username)],
status_code=204,
)
def delete_collection(collection_id: str):
try:
collection_loader.delete(collection_id=collection_id)
return {f"Successfully deleted: {collection_id}"}
except Exception as e:
print(e)
raise HTTPException(status_code=400, detail=(f"{e}"))
collection_loader.delete(collection_id=collection_id)


@app.get("/auth/me")
Expand Down