Skip to content

Commit 15b5b4b

Browse files
Merge pull request #605 from Checkmk/Cleanup-HTTP_Codes
Cleanup of HTTP_Codes
2 parents 4c292cb + 5ad7d2b commit 15b5b4b

File tree

7 files changed

+15
-266
lines changed

7 files changed

+15
-266
lines changed

plugins/module_utils/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, module):
4444
# may be "present", "abesent" or an individual one
4545
self.state = ""
4646

47-
def _fetch(self, code_mapping, endpoint="", data=None, method="GET"):
47+
def _fetch(self, code_mapping="", endpoint="", data=None, method="GET"):
4848
http_mapping = GENERIC_HTTP_CODES.copy()
4949
http_mapping.update(code_mapping)
5050

plugins/module_utils/utils.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@ def result_as_dict(result):
2020

2121

2222
GENERIC_HTTP_CODES = {
23-
204: (True, False, "Successfully executed"),
23+
200: (True, False, "OK: The operation was done successfully"),
24+
204: (True, False, "Operation done successfully. No further output."),
2425
400: (False, True, "Bad request: Parameter or validation failure"),
26+
401: (False, True, "The user is not authorized to do this request"),
2527
403: (False, True, "Forbidden: Configuration via Setup is disabled"),
26-
404: (False, True, "Not found"),
27-
406: (False, True, "Required headers are not satisfied"),
28-
412: (False, True, "If-Match does not match ETag"),
29-
415: (False, True, "Wrong content-type in header"),
30-
428: (False, True, "If-Match header is missing"),
28+
404: (False, True, "Not Found: The requested object has not been found"),
29+
405: (
30+
False,
31+
True,
32+
"This request is only allowed with other HTTP methods",
33+
),
34+
406: (False, True, "The requests accept headers can not be satisfied"),
35+
412: (False, True, "If-Match header doesn't match the object's ETag"),
36+
415: (False, True, "The submitted content-type is not supported"),
37+
428: (False, True, "The required If-Match header is missing"),
38+
500: (False, True, "General Server Error"),
3139
}

plugins/modules/bakery.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,6 @@
9595
result_as_dict,
9696
)
9797

98-
HTTP_CODES = {
99-
# http_code: (changed, failed, "Message")
100-
200: (True, False, "The operation was done successfully."),
101-
204: (
102-
True,
103-
False,
104-
"No Content: Operation done successfully. No further output.",
105-
),
106-
400: (False, True, "Bad Request: Parameter or validation failure."),
107-
403: (False, True, "Forbidden: Configuration via WATO is disabled."),
108-
406: (
109-
False,
110-
True,
111-
"Not Acceptable: The requests accept headers can not be satisfied.",
112-
),
113-
415: (
114-
False,
115-
True,
116-
"Unsupported Media Type: The submitted content-type is not supported.",
117-
),
118-
500: (False, True, "General Server Error."),
119-
}
120-
12198

12299
class BakeryAPI(CheckmkAPI):
123100
def post(self):
@@ -137,7 +114,6 @@ def post(self):
137114
action = "bake_and_sign"
138115

139116
return self._fetch(
140-
code_mapping=HTTP_CODES,
141117
endpoint="/domain-types/agent/actions/%s/invoke" % action,
142118
data=data,
143119
method="POST",

plugins/modules/discovery.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,8 @@
131131
False,
132132
"The service discovery background job has been initialized. Redirecting to the 'Wait for service discovery completion' endpoint.",
133133
),
134-
400: (False, True, "Bad Request."),
135-
403: (False, True, "Forbidden: Configuration via WATO is disabled."),
136134
404: (False, True, "Not Found: Host could not be found."),
137-
406: (False, True, "Not Acceptable."),
138135
409: (False, False, "Conflict: A discovery background job is already running"),
139-
415: (False, True, "Unsupported Media Type."),
140-
500: (False, True, "General Server Error."),
141136
}
142137

143138
HTTP_CODES_SC = {
@@ -148,30 +143,19 @@
148143
False,
149144
"The service discovery is still running. Redirecting to the 'Wait for completion' endpoint.",
150145
),
151-
403: (False, True, "Forbidden: Configuration via Setup is disabled."),
152146
404: (False, False, "Not Found: There is no running service discovery"),
153-
406: (False, True, "Not Acceptable."),
154-
500: (False, True, "General Server Error."),
155147
}
156148

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

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

177161

plugins/modules/password.py

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -132,90 +132,12 @@
132132
# We count 404 not as failed, because we want to know if the password exists or not.
133133
HTTP_CODES_GET = {
134134
# http_code: (changed, failed, "Message")
135-
200: (True, False, "OK: The operation was done successfully."),
136-
400: (False, True, "Bad Request: Parameter or validation failure."),
137-
403: (False, True, "Forbidden: Configuration via Setup is disabled."),
138135
404: (False, False, "Not Found: The requested object has not been found."),
139-
406: (
140-
False,
141-
True,
142-
"Not Acceptable: The requests accept headers can not be satisfied.",
143-
),
144-
415: (
145-
False,
146-
True,
147-
"Unsupported Media Type: The submitted content-type is not supported.",
148-
),
149-
500: (False, True, "General Server Error."),
150136
}
151137

152138
HTTP_CODES_DELETE = {
153139
# http_code: (changed, failed, "Message")
154-
200: (True, False, "OK: The operation was done successfully."),
155-
400: (False, True, "Bad Request: Parameter or validation failure."),
156-
403: (False, True, "Forbidden: Configuration via Setup is disabled."),
157140
404: (False, False, "Not Found: The requested object has not been found."),
158-
406: (
159-
False,
160-
True,
161-
"Not Acceptable: The requests accept headers can not be satisfied.",
162-
),
163-
415: (
164-
False,
165-
True,
166-
"Unsupported Media Type: The submitted content-type is not supported.",
167-
),
168-
500: (False, True, "General Server Error."),
169-
}
170-
171-
HTTP_CODES_CREATE = {
172-
# http_code: (changed, failed, "Message")
173-
200: (True, False, "OK: The operation was done successfully."),
174-
400: (False, True, "Bad Request: Parameter or validation failure."),
175-
403: (False, True, "Forbidden: Configuration via Setup is disabled."),
176-
406: (
177-
False,
178-
True,
179-
"Not Acceptable: The requests accept headers can not be satisfied.",
180-
),
181-
415: (
182-
False,
183-
True,
184-
"Unsupported Media Type: The submitted content-type is not supported.",
185-
),
186-
500: (False, True, "General Server Error."),
187-
}
188-
189-
HTTP_CODES_UPDATE = {
190-
# http_code: (changed, failed, "Message")
191-
200: (
192-
True,
193-
False,
194-
"No Content: Operation was done successfully. No further output",
195-
),
196-
403: (False, True, "Forbidden: Configuration via Setup is disabled."),
197-
404: (False, True, "Not Found: The requested object has not been found."),
198-
406: (
199-
False,
200-
True,
201-
"Not Acceptable: The requests accept headers can not be satisfied.",
202-
),
203-
412: (
204-
False,
205-
True,
206-
"Precondition Failed: The value of the If-Match header doesn't match the object's ETag.",
207-
),
208-
415: (
209-
False,
210-
True,
211-
"Unsupported Media Type: The submitted content-type is not supported.",
212-
),
213-
428: (
214-
False,
215-
True,
216-
"Precondition Required: The required If-Match header is missing.",
217-
),
218-
500: (False, True, "General Server Error."),
219141
}
220142

221143

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

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

261182
return self._fetch(
262-
code_mapping=HTTP_CODES_UPDATE,
263183
endpoint="/objects/password/%s" % self.params.get("name"),
264184
data=data,
265185
method="PUT",

plugins/modules/tag_group.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -138,37 +138,7 @@
138138
# We count 404 not as failed, because we want to know if the taggroup exists or not.
139139
HTTP_CODES_GET = {
140140
# http_code: (changed, failed, "Message")
141-
200: (True, False, "OK: The operation was done successfully."),
142141
404: (False, False, "Not Found: The requested object has not been found."),
143-
500: (False, True, "General Server Error."),
144-
}
145-
146-
HTTP_CODES_DELETE = {
147-
# http_code: (changed, failed, "Message")
148-
405: (
149-
False,
150-
True,
151-
"Method Not Allowed: This request is only allowed with other HTTP methods",
152-
),
153-
500: (False, True, "General Server Error."),
154-
}
155-
156-
HTTP_CODES_CREATE = {
157-
# http_code: (changed, failed, "Message")
158-
200: (True, False, "OK: The operation was done successfully."),
159-
500: (False, True, "General Server Error."),
160-
}
161-
162-
HTTP_CODES_UPDATE = {
163-
# http_code: (changed, failed, "Message")
164-
200: (True, False, "OK: The operation was done successfully."),
165-
401: (False, True, "Unauthorized: The user is not authorized to do this request"),
166-
405: (
167-
False,
168-
True,
169-
"Method Not Allowed: This request is only allowed with other HTTP methods",
170-
),
171-
500: (False, True, "General Server Error."),
172142
}
173143

174144

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

213183
return self._fetch(
214-
code_mapping=HTTP_CODES_CREATE,
215184
endpoint="/domain-types/host_tag_group/collections/all",
216185
data=data,
217186
method="POST",
@@ -223,7 +192,6 @@ def put(self):
223192
data = normalize_data(self.params)
224193

225194
return self._fetch(
226-
code_mapping=HTTP_CODES_UPDATE,
227195
endpoint="/objects/host_tag_group/%s" % self.params.get("name"),
228196
data=data,
229197
method="PUT",
@@ -235,7 +203,6 @@ def delete(self):
235203
data = {}
236204

237205
return self._fetch(
238-
code_mapping=HTTP_CODES_DELETE,
239206
endpoint="/objects/host_tag_group/%s?repair=%s"
240207
% (self.params.get("name"), self.params.get("repair")),
241208
# data=data,

0 commit comments

Comments
 (0)