Skip to content

Commit

Permalink
Replace # Not Implemented yet comments with NotImplementedError excep…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
Edbo849 committed Sep 2, 2024
1 parent 5349826 commit 999c530
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 37 deletions.
24 changes: 14 additions & 10 deletions esgf-consumer/esgf_consumer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
ESGFConsumerNotImplementedPayloadError,
ESGFConsumerUnknownPayloadError,
)
from esgf_consumer.items import create_item, hard_delete_item, update_item
from esgf_consumer.items import (
create_item,
hard_delete_item,
update_item,
soft_delete_item,
)
from esgf_consumer.producers import get_producer

logging.getLogger().setLevel(logging.DEBUG)
Expand Down Expand Up @@ -171,15 +176,14 @@ async def _handle_message(
)
logger.critical("Item %s deleted.", event.data.payload.item_id)

# Not Yet Implemented
# case RevokePayload(method="PATCH"):
# await soft_delete_item(
# event.data.payload.collection_id,
# event.data.payload.item_id,
# settings,
# client,
# )
# logger.critical("Item %s deleted.", event.data.payload.item_id)
case RevokePayload(method="PATCH"):
await soft_delete_item(
event.data.payload.collection_id,
event.data.payload.item_id,
settings,
client,
)
logger.critical("Item %s deleted.", event.data.payload.item_id)

case _:
raise ESGFConsumerUnknownPayloadError
Expand Down
35 changes: 17 additions & 18 deletions esgf-consumer/esgf_consumer/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,28 @@ async def update_item(
return None


# Not Yet Implemented
# async def soft_delete_item(
# collection_id: str,
# item: Item,
# item_id: str,
# settings: Settings,
# client: httpx.AsyncClient,
# ) -> None:
async def soft_delete_item(
collection_id: str,
item: Item,
item_id: str,
settings: Settings,
client: httpx.AsyncClient,
) -> None:

# path = f"collections/{collection_id}/items/{item_id}"
# url = urljoin(str(settings.stac_server), path)
path = f"collections/{collection_id}/items/{item_id}"
url = urljoin(str(settings.stac_server), path)

# patch_data = {"retracted": True}
patch_data = {"retracted": True}

# logger.critical("Revoking %s at %s", getattr(item.properties, "instance_id"), url)
# result = await client.patch(url, content=patch_data, timeout=5)
# if result.status_code < 300:
# logger.critical("Item Revoked")
logger.critical("Revoking %s at %s", getattr(item.properties, "instance_id"), url)
result = await client.patch(url, content=patch_data, timeout=5)
if result.status_code < 300:
logger.critical("Item Revoked")

# else:
# logger.critical("Item not revoked: %s", result.content)
else:
logger.critical("Item not revoked: %s", result.content)

# return None
return None


async def hard_delete_item(
Expand Down
8 changes: 2 additions & 6 deletions esgf-generator/esgf_generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,8 @@ def esgf_delete(
result = client.delete(
f"http://localhost:{NODE_PORTS[node]}/{collection_id}/items/{item_id}"
)
# Not Yet Implemented
# else:
# result = client.patch(
# f"http://localhost:{NODE_PORTS[node]}/{collection_id}/items/{item_id}",
# content={"retracted": True},
# )
else:
raise NotImplementedError("Soft delete is not implemented yet.")
if result.status_code >= 300:
raise Exception(result.content)

Expand Down
5 changes: 2 additions & 3 deletions esgf-transaction-api/esgf_transaction_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,5 @@ async def delete_item(item_id: str, collection_id: str, request: Request) -> Non
logger.info("Deleting %s item", collection_id)
if request.method == "DELETE":
await revoke_item_hard(collection_id, item_id)
# Not yet Implemented
# else:
# await revoke_item_soft(collection_id, item_id)
else:
raise NotImplementedError("Soft delete is not implemented yet.")

0 comments on commit 999c530

Please sign in to comment.