Skip to content

Commit

Permalink
Add 204 as a valid status code for DELETE operation in api.py (#82)
Browse files Browse the repository at this point in the history
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 <eddy.filip@agilebits.com>
  • Loading branch information
alexbartok and edif2008 authored Apr 2, 2024
1 parent c84cb40 commit 9fcaa24
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<Undefined error>")
)
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", "<Undefined error>")
)
return self._module.fail_json(msg=msg)
else:
raise_for_error(info)

Expand Down

0 comments on commit 9fcaa24

Please sign in to comment.