Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def manualvalidation():
"""
In this example you need to call validate() manually
passing received data, Definition (schema: id), specs filename
"""
data = request.json
validate(data, 'User', "test_validation.yml")
return jsonify(data)
def ef():
data = _extract_request_data(interface.exposed_method_args(method))
try:
result = interface.execute(method, data)
if hasattr(result, 'read'):
rlogger.debug('Got response for [%s]: ', flask.g.ebonite_id)
return send_file(result, attachment_filename=getattr(result, 'name', None))
response = {'ok': True, 'data': result}
rlogger.debug('Got response for [%s]: %s', flask.g.ebonite_id, response)
if VALIDATE:
validate(response, specs=spec, definition='response_{}'.format(method))
return jsonify(response)
except ExecutionError as e:
raise FlaskServerError(*e.args)
if not APIKey.get_one(api_key):
if api_key:
app.logger.info('Invalid authorization with API key: {0}...'.format(api_key[0:24]))
else:
app.logger.info('No API key was provided')
raise RedapError(message='Unauthorized', status_code=401)
if method == 'GET': # Inject _params
url = furl(request.url)
inner_kwargs['_params'] = dict(url.query.params)
elif method in ['POST', 'PUT']:
# Inject validated parameters on insert / update operations (if a body is expected)
if any(p for p in spec.parameters if p['name'] == 'body' and p['required']):
if method == 'POST':
validate(request.get_json(), specs=spec.__dict__, validation_error_handler=validation_error)
inner_kwargs['_payload'] = request.get_json()
response = f(*inner_args, **inner_kwargs)
if isinstance(response, str):
app.logger.info(response)
response = {'result': response}
return jsonify(response), status
def manualvalidation_bp():
"""
In this example you need to call validate() manually
passing received data, Definition (schema: id), specs filename
"""
data = request.json
validate(data, 'User', "test_validation.yml")
return jsonify(data)