From 563e30893de06b2cee744694788ea2da60cb01a3 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Wed, 23 Aug 2023 13:37:06 +0200 Subject: cli: add delete http method Add delete function to OgRest class. Enable ogCLI to send HTTP requests using DELETE as request verb. Encapsulates requests python module .delete() method. --- cli/cli.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'cli') diff --git a/cli/cli.py b/cli/cli.py index 6837852..dd6b723 100644 --- a/cli/cli.py +++ b/cli/cli.py @@ -48,6 +48,19 @@ class OgREST(): sys.exit(f"Cannot connect to ogServer: {e}") return r + def delete(self, path, payload): + try: + r = requests.delete(f'{self.URL}{path}', + headers=self.HEADERS, + json=payload) + print(r.text) + if r.status_code != 200: + sys.exit(f"Unsuccessful request to ogServer: " + f"{r.status_code} HTTP status code") + except IOError as e: + sys.exit(f"Cannot connect to ogServer: {e}") + return r + class OgCLI(): def __init__(self, cfg): -- cgit v1.2.3-18-g5258