Commit e7189855 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Add authorization on patch request.

Add check to response code.
parent aa3cde4d
Pipeline #37968 passed with stages
in 1 minute and 13 seconds
......@@ -192,7 +192,7 @@ class WriteJobResultToDrupal(MethodView):
data = patch_calls[patchCall]
try:
response = requests.patch(
url, headers=self.headers, data=json.dumps(data)
url, headers=self.headers, data=json.dumps(data), auth=self.auth
)
except requests.exceptions.RequestException:
message = (
......@@ -205,6 +205,10 @@ class WriteJobResultToDrupal(MethodView):
if response.status_code == 200:
app.logger.debug("Updated: " + url)
result["message"] += "Updated: " + url + "\n"
elif response.status_code == 401:
message = f"Unauthorized access on {url}"
app.logger.error(message)
raise ImportApiError(message)
elif response.status_code == 403:
message = "Not authorized to write to: " + url
app.logger.error(message)
......
......@@ -164,6 +164,10 @@ class WriteTypeReportToDrupal(MethodView):
if response.ok:
app.logger.debug("Updated: " + url)
result["message"] += "Updated: " + url + "\n"
elif response.status_code == 401:
message = f"Unauthorized access on {url}"
app.logger.error(message)
raise ImportApiError(message)
elif response.status_code == 403:
message = f"Authorization Failed: {url}"
app.logger.error(message)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment