Spaces:
Sleeping
Sleeping
fix: delete and logging bugs
Browse files
scribe_python_client/client.py
CHANGED
|
@@ -11,7 +11,7 @@ import pathlib
|
|
| 11 |
import socket, os
|
| 12 |
|
| 13 |
|
| 14 |
-
from .utils import convert_timestamps, send_post_request, send_get_request, decode_jwt_token, querystr_to_json, att2statement
|
| 15 |
from .lineage_graph import create_lineage_graph
|
| 16 |
|
| 17 |
from .constants import (
|
|
@@ -1573,30 +1573,35 @@ class ScribeClient:
|
|
| 1573 |
Delete an attestation by its ID using the DELETE /evidence/{file_id} endpoint.
|
| 1574 |
Returns True if successful, False otherwise. Logs the deletion event.
|
| 1575 |
"""
|
| 1576 |
-
|
| 1577 |
-
|
| 1578 |
-
|
| 1579 |
-
|
| 1580 |
-
|
| 1581 |
-
|
| 1582 |
-
|
| 1583 |
-
|
| 1584 |
-
|
| 1585 |
-
|
| 1586 |
-
|
| 1587 |
-
|
| 1588 |
-
|
| 1589 |
-
|
| 1590 |
-
|
| 1591 |
-
|
| 1592 |
-
|
| 1593 |
-
|
| 1594 |
-
|
| 1595 |
-
|
| 1596 |
-
|
| 1597 |
-
|
| 1598 |
-
|
| 1599 |
-
|
| 1600 |
-
|
| 1601 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1602 |
return False
|
|
|
|
| 11 |
import socket, os
|
| 12 |
|
| 13 |
|
| 14 |
+
from .utils import convert_timestamps, send_post_request, send_get_request, decode_jwt_token, querystr_to_json, att2statement, send_delete_request
|
| 15 |
from .lineage_graph import create_lineage_graph
|
| 16 |
|
| 17 |
from .constants import (
|
|
|
|
| 1573 |
Delete an attestation by its ID using the DELETE /evidence/{file_id} endpoint.
|
| 1574 |
Returns True if successful, False otherwise. Logs the deletion event.
|
| 1575 |
"""
|
| 1576 |
+
try:
|
| 1577 |
+
url = f"{self.base_url}/evidence/{attestation_id}"
|
| 1578 |
+
response = send_delete_request(url, token=self.jwt_token)
|
| 1579 |
+
user = None
|
| 1580 |
+
if hasattr(self, "decoded_token") and self.decoded_token:
|
| 1581 |
+
user = self.decoded_token.get("name") or self.decoded_token.get("preferred_username")
|
| 1582 |
+
|
| 1583 |
+
if response.status_code == 204 or response.status_code == 200:
|
| 1584 |
+
logging.info(f"Successfully deleted attestation {attestation_id}")
|
| 1585 |
+
event = Event(
|
| 1586 |
+
severity="INFO",
|
| 1587 |
+
messageid="Att-Deletion",
|
| 1588 |
+
message=f"Attestation deleted (attestation_id={attestation_id})",
|
| 1589 |
+
user=user,
|
| 1590 |
+
)
|
| 1591 |
+
self.log_event(event)
|
| 1592 |
+
return True
|
| 1593 |
+
else:
|
| 1594 |
+
logging.warning(f"Failed to delete attestation {attestation_id}")
|
| 1595 |
+
event = Event(
|
| 1596 |
+
severity="WARNING",
|
| 1597 |
+
messageid="Att-Deletion",
|
| 1598 |
+
message=f"Attestation deletion failed (attestation_id={attestation_id})",
|
| 1599 |
+
user=user,
|
| 1600 |
+
metadata={"result": {"status": f"{response.status}"}, "error": f"{response.text}"}
|
| 1601 |
+
)
|
| 1602 |
+
self.log_event(event)
|
| 1603 |
+
return False
|
| 1604 |
+
|
| 1605 |
+
except Exception as e:
|
| 1606 |
+
logging.warning(f"Error occurred while deleting attestation {attestation_id}: {e}")
|
| 1607 |
return False
|
scribe_python_client/utils.py
CHANGED
|
@@ -83,7 +83,7 @@ def send_delete_request(url, token=None):
|
|
| 83 |
return response
|
| 84 |
else:
|
| 85 |
logging.warning(f"DELETE request to {url} failed with status code: {response.status_code}, {response.text}")
|
| 86 |
-
return
|
| 87 |
|
| 88 |
except requests.exceptions.RequestException as e:
|
| 89 |
logging.error(f"An error occurred: {e}")
|
|
|
|
| 83 |
return response
|
| 84 |
else:
|
| 85 |
logging.warning(f"DELETE request to {url} failed with status code: {response.status_code}, {response.text}")
|
| 86 |
+
return response
|
| 87 |
|
| 88 |
except requests.exceptions.RequestException as e:
|
| 89 |
logging.error(f"An error occurred: {e}")
|
scribe_python_client/version.py
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
__version__ = "0.2.
|
|
|
|
| 1 |
+
__version__ = "0.2.24"
|