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 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
17 changes: 7 additions & 10 deletions lib/ingestor-api/runtime/src/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ 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)
collection = [
collection.to_dict()
] # pypgstac wants either a string or an Iterable of dicts.
loader.load_collections(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)
collection = [
collection.to_dict()
] # pypgstac wants either a string or an Iterable of dicts.
loader.load_collections(file=collection, insert_mode=Methods.upsert)


def delete(collection_id: str):
Expand Down
23 changes: 6 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,22 @@ 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
2 changes: 1 addition & 1 deletion lib/ingestor-api/runtime/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import boto3
import pydantic
from fastapi.encoders import jsonable_encoder
from pypgstac.db import PgstacDB
from pypgstac.load import Methods
from fastapi.encoders import jsonable_encoder

from .loader import Loader
from .schemas import Ingestion
Expand Down
5 changes: 3 additions & 2 deletions lib/ingestor-api/runtime/tests/test_collection.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
from unittest.mock import Mock, patch

import pytest
import src.collection as collection
from pypgstac.load import Methods
from src.utils import DbCreds
import src.collection as collection
import os


@pytest.fixture()
Expand Down
2 changes: 1 addition & 1 deletion lib/ingestor-api/runtime/tests/test_collection_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_auth_delete_collection(delete, example_stac_collection, client_authenti
headers={"Authorization": f"bearer {token}"},
)
delete.assert_called_once_with(collection_id=example_stac_collection["id"])
assert response.status_code == 200
assert response.status_code == 204


def test_unauth_delete_collection(client, example_stac_collection):
Expand Down
3 changes: 1 addition & 2 deletions lib/ingestor-api/runtime/tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
from typing import TYPE_CHECKING, List
from unittest.mock import call, patch

from fastapi.encoders import jsonable_encoder
import pytest

from fastapi.encoders import jsonable_encoder

if TYPE_CHECKING:
from fastapi.testclient import TestClient
Expand Down
2 changes: 1 addition & 1 deletion lib/ingestor-api/runtime/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from unittest.mock import Mock, patch

import pytest
from pypgstac.load import Methods
from fastapi.encoders import jsonable_encoder
from pypgstac.load import Methods
from src.utils import DbCreds


Expand Down