1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-03-21 20:59:10 +00:00

replace literal HTTP codes with http.HTTPStatus (#11561)

* replace literal HTTP codes with http.HTTPStatus

* add changelog frag
This commit is contained in:
Alexei Znamensky 2026-03-11 10:03:55 +13:00 committed by GitHub
parent 1554f23bfb
commit 7436c0c9ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 135 additions and 78 deletions

View file

@ -13,6 +13,7 @@ from __future__ import annotations
import json
import typing as t
from http import HTTPStatus
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url
@ -116,7 +117,8 @@ class UTM:
returns the info for an object in utm
"""
info, result = self._lookup_entry(self.module, self.request_url)
if info["status"] >= 400:
_status = HTTPStatus(info["status"])
if _status.is_client_error or _status.is_server_error:
self.module.fail_json(result=json.loads(info))
else:
if result is None:
@ -133,7 +135,8 @@ class UTM:
is_changed = False
info, result = self._lookup_entry(self.module, self.request_url)
if info["status"] >= 400:
_status = HTTPStatus(info["status"])
if _status.is_client_error or _status.is_server_error:
self.module.fail_json(result=json.loads(info))
else:
data_as_json_string = self.module.jsonify(self.module.params)
@ -141,7 +144,8 @@ class UTM:
response, info = fetch_url(
self.module, self.request_url, method="POST", headers=combined_headers, data=data_as_json_string
)
if info["status"] >= 400:
_status = HTTPStatus(info["status"])
if _status.is_client_error or _status.is_server_error:
self.module.fail_json(msg=json.loads(info["body"]))
is_changed = True
result = self._clean_result(json.loads(response.read()))
@ -154,7 +158,8 @@ class UTM:
headers=combined_headers,
data=data_as_json_string,
)
if info["status"] >= 400:
_status = HTTPStatus(info["status"])
if _status.is_client_error or _status.is_server_error:
self.module.fail_json(msg=json.loads(info["body"]))
is_changed = True
result = self._clean_result(json.loads(response.read()))
@ -187,7 +192,8 @@ class UTM:
headers={"Accept": "application/json", "X-Restd-Err-Ack": "all"},
data=self.module.jsonify(self.module.params),
)
if info["status"] >= 400:
_status = HTTPStatus(info["status"])
if _status.is_client_error or _status.is_server_error:
self.module.fail_json(msg=json.loads(info["body"]))
else:
is_changed = True