From 999c53000a2fbb0ca27aa2c83b1d2da0b229c251 Mon Sep 17 00:00:00 2001 From: Edbo849 Date: Mon, 2 Sep 2024 15:25:06 +0100 Subject: [PATCH] Replace # Not Implemented yet comments with NotImplementedError exceptions --- esgf-consumer/esgf_consumer/__init__.py | 24 +++++++------ esgf-consumer/esgf_consumer/items.py | 35 +++++++++---------- esgf-generator/esgf_generator/cli.py | 8 ++--- .../esgf_transaction_api/main.py | 5 ++- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/esgf-consumer/esgf_consumer/__init__.py b/esgf-consumer/esgf_consumer/__init__.py index 181443f..b640018 100644 --- a/esgf-consumer/esgf_consumer/__init__.py +++ b/esgf-consumer/esgf_consumer/__init__.py @@ -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) @@ -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 diff --git a/esgf-consumer/esgf_consumer/items.py b/esgf-consumer/esgf_consumer/items.py index 93a46ad..1cec23e 100644 --- a/esgf-consumer/esgf_consumer/items.py +++ b/esgf-consumer/esgf_consumer/items.py @@ -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( diff --git a/esgf-generator/esgf_generator/cli.py b/esgf-generator/esgf_generator/cli.py index 3a596ac..64c7990 100644 --- a/esgf-generator/esgf_generator/cli.py +++ b/esgf-generator/esgf_generator/cli.py @@ -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) diff --git a/esgf-transaction-api/esgf_transaction_api/main.py b/esgf-transaction-api/esgf_transaction_api/main.py index cbc725e..de9c292 100644 --- a/esgf-transaction-api/esgf_transaction_api/main.py +++ b/esgf-transaction-api/esgf_transaction_api/main.py @@ -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.")