Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup of HTTP_Codes #605

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, module):
# may be "present", "abesent" or an individual one
self.state = ""

def _fetch(self, code_mapping, endpoint="", data=None, method="GET"):
def _fetch(self, code_mapping="", endpoint="", data=None, method="GET"):
Max-checkmk marked this conversation as resolved.
Show resolved Hide resolved
http_mapping = GENERIC_HTTP_CODES.copy()
http_mapping.update(code_mapping)

Expand Down
20 changes: 14 additions & 6 deletions plugins/module_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@ def result_as_dict(result):


GENERIC_HTTP_CODES = {
204: (True, False, "Successfully executed"),
200: (True, False, "OK: The operation was done successfully"),
204: (True, False, "Operation done successfully. No further output."),
400: (False, True, "Bad request: Parameter or validation failure"),
401: (False, True, "The user is not authorized to do this request"),
403: (False, True, "Forbidden: Configuration via Setup is disabled"),
404: (False, True, "Not found"),
406: (False, True, "Required headers are not satisfied"),
412: (False, True, "If-Match does not match ETag"),
415: (False, True, "Wrong content-type in header"),
428: (False, True, "If-Match header is missing"),
404: (False, True, "Not Found: The requested object has not been found"),
405: (
False,
True,
"This request is only allowed with other HTTP methods",
),
406: (False, True, "The requests accept headers can not be satisfied"),
412: (False, True, "If-Match header doesn't match the object's ETag"),
415: (False, True, "The submitted content-type is not supported"),
428: (False, True, "The required If-Match header is missing"),
500: (False, True, "General Server Error"),
}
24 changes: 0 additions & 24 deletions plugins/modules/bakery.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,6 @@
result_as_dict,
)

HTTP_CODES = {
# http_code: (changed, failed, "Message")
200: (True, False, "The operation was done successfully."),
204: (
True,
False,
"No Content: Operation done successfully. No further output.",
),
400: (False, True, "Bad Request: Parameter or validation failure."),
403: (False, True, "Forbidden: Configuration via WATO is disabled."),
406: (
False,
True,
"Not Acceptable: The requests accept headers can not be satisfied.",
),
415: (
False,
True,
"Unsupported Media Type: The submitted content-type is not supported.",
),
500: (False, True, "General Server Error."),
}


class BakeryAPI(CheckmkAPI):
def post(self):
Expand All @@ -137,7 +114,6 @@ def post(self):
action = "bake_and_sign"

return self._fetch(
code_mapping=HTTP_CODES,
endpoint="/domain-types/agent/actions/%s/invoke" % action,
data=data,
method="POST",
Expand Down
16 changes: 0 additions & 16 deletions plugins/modules/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,8 @@
False,
"The service discovery background job has been initialized. Redirecting to the 'Wait for service discovery completion' endpoint.",
),
400: (False, True, "Bad Request."),
403: (False, True, "Forbidden: Configuration via WATO is disabled."),
404: (False, True, "Not Found: Host could not be found."),
406: (False, True, "Not Acceptable."),
409: (False, False, "Conflict: A discovery background job is already running"),
415: (False, True, "Unsupported Media Type."),
500: (False, True, "General Server Error."),
}

HTTP_CODES_SC = {
Expand All @@ -147,30 +142,19 @@
False,
"The service discovery is still running. Redirecting to the 'Wait for completion' endpoint.",
),
403: (False, True, "Forbidden: Configuration via Setup is disabled."),
404: (False, False, "Not Found: There is no running service discovery"),
406: (False, True, "Not Acceptable."),
500: (False, True, "General Server Error."),
}

HTTP_CODES_BULK = {
# http_code: (changed, failed, "Message")
200: (True, False, "Discovery successful."),
400: (False, True, "Bad Request."),
403: (False, True, "Forbidden: Configuration via WATO is disabled."),
406: (False, True, "Not Acceptable."),
409: (False, False, "Conflict: A bulk discovery job is already active"),
415: (False, True, "Unsupported Media Type."),
500: (False, True, "General Server Error."),
}

HTTP_CODES_BULK_SC = {
# http_code: (changed, failed, "Message")
200: (True, False, "The service discovery has been completed."),
403: (False, True, "Forbidden: Configuration via WATO is disabled."),
404: (False, False, "Not Found: There is no running bulk_discovery job"),
406: (False, True, "Not Acceptable."),
500: (False, True, "General Server Error."),
}


Expand Down
80 changes: 0 additions & 80 deletions plugins/modules/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,90 +132,12 @@
# We count 404 not as failed, because we want to know if the password exists or not.
HTTP_CODES_GET = {
# http_code: (changed, failed, "Message")
200: (True, False, "OK: The operation was done successfully."),
400: (False, True, "Bad Request: Parameter or validation failure."),
403: (False, True, "Forbidden: Configuration via Setup is disabled."),
404: (False, False, "Not Found: The requested object has not been found."),
406: (
False,
True,
"Not Acceptable: The requests accept headers can not be satisfied.",
),
415: (
False,
True,
"Unsupported Media Type: The submitted content-type is not supported.",
),
500: (False, True, "General Server Error."),
}

HTTP_CODES_DELETE = {
# http_code: (changed, failed, "Message")
200: (True, False, "OK: The operation was done successfully."),
400: (False, True, "Bad Request: Parameter or validation failure."),
403: (False, True, "Forbidden: Configuration via Setup is disabled."),
404: (False, False, "Not Found: The requested object has not been found."),
406: (
False,
True,
"Not Acceptable: The requests accept headers can not be satisfied.",
),
415: (
False,
True,
"Unsupported Media Type: The submitted content-type is not supported.",
),
500: (False, True, "General Server Error."),
}

HTTP_CODES_CREATE = {
# http_code: (changed, failed, "Message")
200: (True, False, "OK: The operation was done successfully."),
400: (False, True, "Bad Request: Parameter or validation failure."),
403: (False, True, "Forbidden: Configuration via Setup is disabled."),
406: (
False,
True,
"Not Acceptable: The requests accept headers can not be satisfied.",
),
415: (
False,
True,
"Unsupported Media Type: The submitted content-type is not supported.",
),
500: (False, True, "General Server Error."),
}

HTTP_CODES_UPDATE = {
# http_code: (changed, failed, "Message")
200: (
True,
False,
"No Content: Operation was done successfully. No further output",
),
403: (False, True, "Forbidden: Configuration via Setup is disabled."),
404: (False, True, "Not Found: The requested object has not been found."),
406: (
False,
True,
"Not Acceptable: The requests accept headers can not be satisfied.",
),
412: (
False,
True,
"Precondition Failed: The value of the If-Match header doesn't match the object's ETag.",
),
415: (
False,
True,
"Unsupported Media Type: The submitted content-type is not supported.",
),
428: (
False,
True,
"Precondition Required: The required If-Match header is missing.",
),
500: (False, True, "General Server Error."),
}


Expand All @@ -236,7 +158,6 @@ def post(self):
data = {key: val for key, val in data.items() if val}

return self._fetch(
code_mapping=HTTP_CODES_CREATE,
endpoint="/domain-types/password/collections/all",
data=data,
method="POST",
Expand All @@ -259,7 +180,6 @@ def put(self):
data = {key: val for key, val in data.items() if val}

return self._fetch(
code_mapping=HTTP_CODES_UPDATE,
endpoint="/objects/password/%s" % self.params.get("name"),
data=data,
method="PUT",
Expand Down
33 changes: 0 additions & 33 deletions plugins/modules/tag_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,37 +138,7 @@
# We count 404 not as failed, because we want to know if the taggroup exists or not.
HTTP_CODES_GET = {
# http_code: (changed, failed, "Message")
200: (True, False, "OK: The operation was done successfully."),
404: (False, False, "Not Found: The requested object has not been found."),
500: (False, True, "General Server Error."),
}

HTTP_CODES_DELETE = {
# http_code: (changed, failed, "Message")
405: (
False,
True,
"Method Not Allowed: This request is only allowed with other HTTP methods",
),
500: (False, True, "General Server Error."),
}

HTTP_CODES_CREATE = {
# http_code: (changed, failed, "Message")
200: (True, False, "OK: The operation was done successfully."),
500: (False, True, "General Server Error."),
}

HTTP_CODES_UPDATE = {
# http_code: (changed, failed, "Message")
200: (True, False, "OK: The operation was done successfully."),
401: (False, True, "Unauthorized: The user is not authorized to do this request"),
405: (
False,
True,
"Method Not Allowed: This request is only allowed with other HTTP methods",
),
500: (False, True, "General Server Error."),
}


Expand Down Expand Up @@ -211,7 +181,6 @@ def post(self):
data["ident"] = self.params.get("name")

return self._fetch(
code_mapping=HTTP_CODES_CREATE,
endpoint="/domain-types/host_tag_group/collections/all",
data=data,
method="POST",
Expand All @@ -223,7 +192,6 @@ def put(self):
data = normalize_data(self.params)

return self._fetch(
code_mapping=HTTP_CODES_UPDATE,
endpoint="/objects/host_tag_group/%s" % self.params.get("name"),
data=data,
method="PUT",
Expand All @@ -235,7 +203,6 @@ def delete(self):
data = {}

return self._fetch(
code_mapping=HTTP_CODES_DELETE,
endpoint="/objects/host_tag_group/%s?repair=%s"
% (self.params.get("name"), self.params.get("repair")),
# data=data,
Expand Down
Loading
Loading