Skip to content

Commit

Permalink
Fixed errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Edbo849 committed Aug 30, 2024
1 parent 629c245 commit 16b0b2a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 38 deletions.
17 changes: 9 additions & 8 deletions esgf-consumer/esgf_consumer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,15 @@ async def _handle_message(
)
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)
# 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 _:
raise ESGFConsumerUnknownPayloadError
Expand Down
35 changes: 18 additions & 17 deletions esgf-consumer/esgf_consumer/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,29 @@ async def update_item(
return None


async def soft_delete_item(
collection_id: str,
item: Item,
item_id: str,
settings: Settings,
client: httpx.AsyncClient,
) -> None:
# Not Yet Implemented
# 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
11 changes: 6 additions & 5 deletions esgf-generator/esgf_generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@ def esgf_delete(
result = client.delete(
f"http://localhost:{NODE_PORTS[node]}/{collection_id}/items/{item_id}"
)
else:
result = client.patch(
f"http://localhost:{NODE_PORTS[node]}/{collection_id}/items/{item_id}",
content={"retracted": True},
)
# Not Yet Implemented
# else:
# result = client.patch(
# f"http://localhost:{NODE_PORTS[node]}/{collection_id}/items/{item_id}",
# content={"retracted": True},
# )
if result.status_code >= 300:
raise Exception(result.content)

Expand Down
18 changes: 10 additions & 8 deletions esgf-transaction-api/esgf_transaction_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,13 @@ async def modify_item(collection_id: str, item: Item, item_id: str) -> None:
await post_message(event)


async def revoke_item_soft(collection_id: str, item_id: str) -> None:
payload = RevokePayload(
method="PATCH", collection_id=collection_id, item_id=item_id
)
event = item_body(payload)
await post_message(event)
# Not Yet Implemented
# async def revoke_item_soft(collection_id: str, item_id: str) -> None:
# payload = RevokePayload(
# method="PATCH", collection_id=collection_id, item_id=item_id
# )
# event = item_body(payload)
# await post_message(event)


async def revoke_item_hard(collection_id: str, item_id: str) -> None:
Expand Down Expand Up @@ -194,5 +195,6 @@ 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)
else:
await revoke_item_soft(collection_id, item_id)
# Not yet Implemented
# else:
# await revoke_item_soft(collection_id, item_id)

0 comments on commit 16b0b2a

Please sign in to comment.