Commit 1d5b30ec authored by Robin Knapp's avatar Robin Knapp

Fix: forwarding url now formatted correctly

parent fd20d5f0
......@@ -58,7 +58,7 @@ def create_app():
cache.init_app(app)
app.config['APP_CACHE'] = cache # to access cache from different modules
app.logger.info('Setup of Flask app was successful')
app.logger.info(f'Setup of Flask app in [{config.DEPLOYMENT_ENV}] mode was successful')
@app.before_request
def before_request():
......
......@@ -2,7 +2,7 @@
import os
DEPLOYMENT_ENV = 'PROD' # PROD or DEV
DEPLOYMENT_ENV = 'DEV' # PROD or DEV
APP_CONFIG = {
'SPECS_TIMEOUT_SEC': os.environ.get('SPECS_TIMEOUT_SEC', 10),
......
......@@ -10,6 +10,8 @@ from src.logic import ValidationException, Creator, Updater
validation_v2_entities = Blueprint('val_v2_ent', __name__, url_prefix='/validation/v2/entities')
historic_validation_v2_entities = Blueprint('hist_v2_ent', __name__, url_prefix='/historic/validation/v2/entities')
FORWARD_URL = '{endpoint}/v2/entities/{url}'
def validate_post_v2(model: dict, cache: flask_caching.Cache):
"""
......@@ -119,9 +121,9 @@ def get_validation_v2_entities(url):
if request.data:
raise ValidationErrorResponse(msg=f'GET-Request must not contain data', log=False)
if request.blueprint == 'val_v2_ent':
forward_url = f'{current_app.config["PLATFORM_ENDPOINT"]}{request.full_path}'
forward_url = FORWARD_URL.format(endpoint=current_app.config["PLATFORM_ENDPOINT"], url=url)
else:
forward_url = f'{current_app.config["PLATFORM_ENDPOINT_HISTORIC"]}{request.full_path}'
forward_url = FORWARD_URL.format(endpoint=current_app.config["PLATFORM_ENDPOINT_HISTORIC"], url=url)
return send_to_platform(forward_url=forward_url)
......@@ -129,7 +131,7 @@ def get_validation_v2_entities(url):
@validation_v2_entities.route('/<path:url>', methods=["DELETE"])
def delete_validation_v2_entities(url):
if request.blueprint == 'val_v2_ent':
forward_url = f'{current_app.config["PLATFORM_ENDPOINT"]}{request.full_path}'
forward_url = FORWARD_URL.format(endpoint=current_app.config["PLATFORM_ENDPOINT"], url=url)
else:
forward_url = f'{current_app.config["PLATFORM_ENDPOINT_HISTORIC"]}{request.full_path}'
return send_to_platform(forward_url=forward_url)
......@@ -139,7 +141,7 @@ def delete_validation_v2_entities(url):
@validation_v2_entities.route('/<path:url>', methods=["OPTIONS"])
def options_validation_v2_entities(url):
if request.blueprint == 'val_v2_ent':
forward_url = f'{current_app.config["PLATFORM_ENDPOINT"]}{request.full_path}'
forward_url = FORWARD_URL.format(endpoint=current_app.config["PLATFORM_ENDPOINT"], url=url)
else:
forward_url = f'{current_app.config["PLATFORM_ENDPOINT_HISTORIC"]}{request.full_path}'
return send_to_platform(forward_url=forward_url)
......@@ -151,9 +153,9 @@ def put_validation_v2_entities(url):
model = json.loads(request.data.decode('UTF-8')) # type = dict
if request.blueprint == 'val_v2_ent':
forward_url = f'{current_app.config["PLATFORM_ENDPOINT"]}{request.full_path}'
forward_url = FORWARD_URL.format(endpoint=current_app.config["PLATFORM_ENDPOINT"], url=url)
else:
forward_url = f'{current_app.config["PLATFORM_ENDPOINT_HISTORIC"]}{request.full_path}'
forward_url = FORWARD_URL.format(endpoint=current_app.config["PLATFORM_ENDPOINT_HISTORIC"], url=url)
# detect patch-request
if extract_modelname_from_url(url) and not model.get('id') and not model.get('type'):
......@@ -184,9 +186,9 @@ def patch_validation_v2_entities(url):
model = ast.literal_eval(request.data.decode('UTF-8')) # dict or list
if request.blueprint == 'val_v2_ent':
forward_url = f'{current_app.config["PLATFORM_ENDPOINT"]}{request.full_path}'
forward_url = FORWARD_URL.format(endpoint=current_app.config["PLATFORM_ENDPOINT"], url=url)
else:
forward_url = f'{current_app.config["PLATFORM_ENDPOINT_HISTORIC"]}{request.full_path}'
forward_url = FORWARD_URL.format(endpoint=current_app.config["PLATFORM_ENDPOINT_HISTORIC"], url=url)
if not extract_modelname_from_url(url) or model.get('id') or model.get('type'):
raise ValidationErrorResponse(msg='Malformed PATCH request', module=__name__)
......@@ -211,7 +213,7 @@ def post_validation_v2_entities(url):
if isinstance(model, list):
raise ValidationErrorResponse(msg=f'None-historic api does not support json-array currently.',
module=__name__)
forward_url = f'{current_app.config["PLATFORM_ENDPOINT"]}{request.full_path}'
forward_url = FORWARD_URL.format(endpoint=current_app.config["PLATFORM_ENDPOINT"], url=url)
try:
validate_post_v2(model=model, cache=current_app.config.get('APP_CACHE'))
except ValidationException as vex:
......@@ -219,7 +221,7 @@ def post_validation_v2_entities(url):
log=False)
else: # historic api
forward_url = f'{current_app.config["PLATFORM_ENDPOINT_HISTORIC"]}{request.full_path}'
forward_url = FORWARD_URL.format(endpoint=current_app.config["PLATFORM_ENDPOINT_HISTORIC"], url=url)
if isinstance(model, list):
for m in model:
try:
......
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