Commit d92989ed authored by Robin Knapp's avatar Robin Knapp

Tested and debugged

parent fc7b4647
......@@ -40,10 +40,10 @@ def create_app():
return jsonify(code=200, dev=True)
else:
app.config.from_mapping(config.APP_CONFIG)
log_file_handler = TimedRotatingFileHandler(filename=app.config['LOG_FILE_NAME'],
when=app.config['LOG_WHEN'],
backupCount=app.config['LOG_FILE_BACKUP_COUNT'],
utc=app.config['LOG_FILE_UTC_TIME'])
log_file_handler = TimedRotatingFileHandler(filename=config.LOG_CONFIG['LOG_FILE_NAME'],
when=config.LOG_CONFIG['LOG_WHEN'],
backupCount=config.LOG_CONFIG['LOG_BACKUP_COUNT'],
utc=config.LOG_CONFIG['LOG_UTC_TIME'])
# configure logging
log_file_handler.setFormatter(FORMATTER)
......
......@@ -120,7 +120,7 @@ def get_validation_v2_entities(url):
if request.blueprint == 'val_v2_ent':
forward_url = f'{current_app.config["PLATFORM_ENDPOINT"]}{request.full_path}'
else:
forward_url = f'{current_app.config["PLATFORM_HISTORIC_ENDPOINT"]}{request.full_path}'
forward_url = f'{current_app.config["PLATFORM_ENDPOINT_HISTORIC"]}{request.full_path}'
return send_to_platform(forward_url=forward_url)
......@@ -130,7 +130,7 @@ def delete_validation_v2_entities(url):
if request.blueprint == 'val_v2_ent':
forward_url = f'{current_app.config["PLATFORM_ENDPOINT"]}{request.full_path}'
else:
forward_url = f'{current_app.config["PLATFORM_HISTORIC_ENDPOINT"]}{request.full_path}'
forward_url = f'{current_app.config["PLATFORM_ENDPOINT_HISTORIC"]}{request.full_path}'
return send_to_platform(forward_url=forward_url)
......@@ -140,7 +140,7 @@ def options_validation_v2_entities(url):
if request.blueprint == 'val_v2_ent':
forward_url = f'{current_app.config["PLATFORM_ENDPOINT"]}{request.full_path}'
else:
forward_url = f'{current_app.config["PLATFORM_HISTORIC_ENDPOINT"]}{request.full_path}'
forward_url = f'{current_app.config["PLATFORM_ENDPOINT_HISTORIC"]}{request.full_path}'
return send_to_platform(forward_url=forward_url)
......@@ -152,7 +152,7 @@ def put_validation_v2_entities(url):
if request.blueprint == 'val_v2_ent':
forward_url = f'{current_app.config["PLATFORM_ENDPOINT"]}{request.full_path}'
else:
forward_url = f'{current_app.config["PLATFORM_HISTORIC_ENDPOINT"]}{request.full_path}'
forward_url = f'{current_app.config["PLATFORM_ENDPOINT_HISTORIC"]}{request.full_path}'
# detect patch-request
if extract_modelname_from_url(url) and not model.get('id') and not model.get('type'):
......@@ -185,7 +185,7 @@ def patch_validation_v2_entities(url):
if request.blueprint == 'val_v2_ent':
forward_url = f'{current_app.config["PLATFORM_ENDPOINT"]}{request.full_path}'
else:
forward_url = f'{current_app.config["PLATFORM_HISTORIC_ENDPOINT"]}{request.full_path}'
forward_url = f'{current_app.config["PLATFORM_ENDPOINT_HISTORIC"]}{request.full_path}'
if not extract_modelname_from_url(url) or model.get('id') or model.get('type'):
raise ValidationErrorResponse(msg='Malformed PATCH request', module=__name__)
......@@ -218,7 +218,7 @@ def post_validation_v2_entities(url):
log=False)
else: # historic api
forward_url = f'{current_app.config["PLATFORM_HISTORIC_ENDPOINT"]}{request.full_path}'
forward_url = f'{current_app.config["PLATFORM_ENDPOINT_HISTORIC"]}{request.full_path}'
if isinstance(model, list):
for m in model:
try:
......
......@@ -280,26 +280,26 @@ class Converter(object):
nav = blueprint[v2_model_key]['nav']
cmds = nav.split('&')
# TODO quickfix beseitigen
# geo properties need special case due to their special syntax
if v2_model_key.lower() == 'location':
i = 0
if v2_model_value['type'] == "geo:json":
kv_model['location'] = v2_model_value['value']
elif v2_model_value['type'] == "geo:polygon":
kv_model['location'] = v2_model_value
kv_model['location'].pop("metadata")
if not blueprint[v2_model_key]["attributeType"].lower() == 'location':
current_app.logger.debug(f"comparison with `location` in blueprint led to error")
raise ValidationException(extern=f'Internal error for {v2_model_key}'
, module=__name__, func='Converter.convert_v2_to_kv')
kv_model['location'] = v2_model_value
kv_model['location'].pop("metadata")
continue
for cmd in cmds:
if cmd.__contains__('=='):
blueprint_attr, v2_model_attr = cmd.split('==')
if blueprint_attr.lower() == 'metadata':
# if metadata = {} -> len() == 0; if metadata = None -> len() == TypeError
try:
len(v2_model_value.get('metadata'))
except TypeError:
raise ValidationException(extern=f'{v2_model_key} is missing the "metadata" attribute'
, module=__name__, func='Converte.convert_v2_to_kv')
# if not {} == true, len({}) == 0
meta = v2_model_value['metadata']
if not isinstance(meta, dict):
raise ValidationException(extern=f'Malformed `metadata` attribute in `{v2_model_key}` '
, module=__name__, func='Converter.convert_v2_to_kv')
elif not blueprint[v2_model_key][blueprint_attr] == v2_model_value[v2_model_attr]:
raise ValidationException(extern=f'{v2_model[v2_model_attr]} is not compliant to model.'
......
""" Validation logic for Fiware models."""
import re
import ast
from flask import current_app
from json import loads, JSONDecodeError
import re
from abc import ABC, abstractmethod
from typing import Union
from flask import current_app
class ValidationException(Exception):
""" Serves as base class for collecting all kinds of Exceptions that might occur during the evaluation process
......@@ -133,7 +133,7 @@ class StructuredValue(Validator):
ValueError if value is not a dict.
"""
try:
res = literal_eval(value)
res = ast.literal_eval(value)
if not isinstance(res, dict) and not isinstance(res, list):
raise ValueError("Structured Value needs to be in form of key-value-pairs or as listed values")
......@@ -209,7 +209,7 @@ class Enum(Validator):
# print(f'validate enum {value}')
# prepare_expression() will make sure value is type list so no further checking here
try:
value = literal_eval(value)
value = ast.literal_eval(value)
duplicates = []
# search for duplicates by using list as a stack
while len(value) > 0:
......
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