From 340a77a4f120cc92192e07b95e1d4b342749cf50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20N=C3=A4slund?= Date: Wed, 16 Nov 2022 22:24:22 +0100 Subject: Better error handling, the server already has this but defence in depth is always good --- src/soc_collector/soc_collector_cli.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/soc_collector/soc_collector_cli.py b/src/soc_collector/soc_collector_cli.py index b579108..2398e4f 100644 --- a/src/soc_collector/soc_collector_cli.py +++ b/src/soc_collector/soc_collector_cli.py @@ -115,6 +115,11 @@ def replace_action(data: str) -> None: """ json_data = json_load_data(data) + + if "_id" not in json_data: + print("ERROR: '_id' key not in data") + app_exit(1) + req = requests.put(f"{API_URL}/sc/v0", json=json_data, headers={"API-KEY": API_KEY}, timeout=5, verify=ROOT_CA_FILE) # Check status @@ -136,6 +141,11 @@ def insert_action(data: str) -> None: """ json_data = json_load_data(data) + + if "_id" in json_data: + print("ERROR: '_id' key in data") + app_exit(1) + req = requests.post( f"{API_URL}/sc/v0", json=json_data, headers={"API-KEY": API_KEY}, timeout=5, verify=ROOT_CA_FILE ) -- cgit v1.1