From 9fcaa2401034def9939d5e3080c29df07798cb2b Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 2 Apr 2024 11:57:44 +0200 Subject: [PATCH] Add 204 as a valid status code for DELETE operation in api.py (#82) As per the 1Password Connect Server API reference, the expected status code for DELETE operation is 204. api.py would always expect a 200 status code, so a successful DELETE operation incorrectly register as a failure. This commit adds 204 as a success status code. Ref: https://developer.1password.com/docs/connect/connect-api-reference/#delete-an-item Co-authored-by: Eddy Filip --- plugins/module_utils/api.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/plugins/module_utils/api.py b/plugins/module_utils/api.py index 6c69614..203a8ca 100644 --- a/plugins/module_utils/api.py +++ b/plugins/module_utils/api.py @@ -51,14 +51,15 @@ def _send_request(self, path, method="GET", data=None, params=None): response_body = {} resp, info = fetch_url(self._module, **fetch_kwargs) - if info.get("status") == 200: - try: - response_body = json.loads(resp.read().decode("utf-8")) - except (AttributeError, ValueError): - msg = "Server returned error with invalid JSON: {err}".format( - err=info.get("msg", "") - ) - return self._module.fail_json(msg=msg) + if info.get("status") in [200, 204]: + if info.get("status") == 200: + try: + response_body = json.loads(resp.read().decode("utf-8")) + except (AttributeError, ValueError): + msg = "Server returned error with invalid JSON: {err}".format( + err=info.get("msg", "") + ) + return self._module.fail_json(msg=msg) else: raise_for_error(info)