Due to a scheduled upgrade to version 14.10, GitLab will be unavailabe on Monday 30.05., from 19:00 until 20:00.

Commit 06cabe33 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Added authentication to clear cache request for test & stage systems.

parent 061ea6e9
Pipeline #32164 passed with stages
in 2 minutes and 24 seconds
......@@ -2,9 +2,21 @@ from flask_restful import Resource, current_app
import requests
import traceback
from requests.auth import HTTPBasicAuth
class ClearCache(Resource):
def __init__(self):
self.logger = current_app.logger
self.headers = {
'X-API-Key': current_app.config['drupal-api-key']
}
user = current_app.config['drupal-user']
password = current_app.config['drupal-password']
self.auth = HTTPBasicAuth(user, password)
self.url = current_app.config['drupal-api-url'] + current_app.config['clear-cache-url']
def get(self):
"""
Tell drupal to clear the import-process-cache
......@@ -18,26 +30,24 @@ class ClearCache(Resource):
description: Failure tha call to drupal could neo be executed
"""
uri = current_app.config['drupal-api-url'] + current_app.config['clear-cache-url']
headers = {'X-API-Key': current_app.config['drupal-api-key']}
try:
response = requests.get(uri, headers=headers)
response = requests.get(self.url, headers=self.headers, auth=self.auth)
except Exception as ex:
msg = 'Exception while calling ' + uri + ': ' + str(ex) + '\n' + \
msg = 'Exception while calling ' + self.url + ': ' + str(ex) + '\n' + \
traceback.format_exc()
current_app.logger.error(msg)
self.logger.error(msg)
return {
'response': response.content.decode("utf-8"),
'response': msg,
}, 500
if response.status_code != 200:
current_app.logger.debug('there was an unexpected behaviour calling ' + uri)
current_app.logger.debug('statuscode: ' + str(response.status_code) + ' content: ' +
response.content.decode('utf-8'))
if response.ok:
self.logger.debug('successfully called ' + self.url)
return {
'content': response.content.decode("utf-8"),
}, response.status_code
else:
current_app.logger.debug('successfully called ' + uri)
self.logger.error('Clearing Cache Failed')
self.logger.error('statuscode: ' + str(response.status_code) + ' content: ' +
response.content.decode('utf-8'))
return {
'content': response.content.decode("utf-8"),
}, 200
}, response.status_code
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