diff --git a/plugins/module_utils/api.py b/plugins/module_utils/api.py index a16f3c69d..bdb01927b 100644 --- a/plugins/module_utils/api.py +++ b/plugins/module_utils/api.py @@ -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"): http_mapping = GENERIC_HTTP_CODES.copy() http_mapping.update(code_mapping) diff --git a/plugins/module_utils/utils.py b/plugins/module_utils/utils.py index bbdf05a88..5412e3df8 100644 --- a/plugins/module_utils/utils.py +++ b/plugins/module_utils/utils.py @@ -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"), } diff --git a/plugins/modules/bakery.py b/plugins/modules/bakery.py index 964d73bd6..32eaff7d2 100644 --- a/plugins/modules/bakery.py +++ b/plugins/modules/bakery.py @@ -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): @@ -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", diff --git a/plugins/modules/discovery.py b/plugins/modules/discovery.py index a38197f9b..92603365d 100644 --- a/plugins/modules/discovery.py +++ b/plugins/modules/discovery.py @@ -131,13 +131,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 = { @@ -148,30 +143,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."), } diff --git a/plugins/modules/password.py b/plugins/modules/password.py index 77f4e824b..16774ab96 100644 --- a/plugins/modules/password.py +++ b/plugins/modules/password.py @@ -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."), } @@ -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", @@ -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", diff --git a/plugins/modules/tag_group.py b/plugins/modules/tag_group.py index 90f61a36a..e3e21605d 100644 --- a/plugins/modules/tag_group.py +++ b/plugins/modules/tag_group.py @@ -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."), } @@ -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", @@ -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", @@ -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, diff --git a/plugins/modules/timeperiod.py b/plugins/modules/timeperiod.py index 11db106dc..19d3da4ec 100644 --- a/plugins/modules/timeperiod.py +++ b/plugins/modules/timeperiod.py @@ -148,110 +148,7 @@ # We count 404 not as failed, because we want to know if the time period 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") - 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 Setup is disabled."), - 404: (False, True, "Not Found: The requested object has not been found."), - 405: ( - False, - True, - "Method Not Allowed: This request is only allowed with other HTTP methods", - ), - 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."), -} - -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."), - 405: ( - False, - True, - "Method Not Allowed: This request is only allowed with other HTTP methods", - ), - 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."), } updatevalues = ("alias", "active_time_ranges", "exceptions", "exclude") @@ -272,7 +169,6 @@ def post(self): data["exclude"] = self.params.get("exclude") return self._fetch( - code_mapping=HTTP_CODES_CREATE, endpoint="/domain-types/time_period/collections/all", data=data, method="POST", @@ -299,7 +195,6 @@ def put(self, existingalias): data["exclude"] = self.params.get("exclude") return self._fetch( - code_mapping=HTTP_CODES_UPDATE, endpoint="/objects/time_period/%s" % self.params.get("name"), data=data, method="PUT", @@ -311,7 +206,6 @@ def delete(self): data = {} return self._fetch( - code_mapping=HTTP_CODES_DELETE, endpoint="/objects/time_period/%s" % self.params.get("name"), data=data, method="DELETE",