"""Validation utils.""" from functools import wraps from flask import request from owsresponse import response from owsresponse.adaptors.flask import flaskify from account.constants import header def reject_grass_headers(f): """Decorator that rejects grass headers. Returns: callable: the wrapped function. """ @wraps(f) def _validate(*args, **kwargs): account_type = request.headers.get(header.GRASS_ACCOUNT_TYPE) account_id = request.headers.get(header.GRASS_ACCOUNT_ID) if account_type or account_id: return flaskify( response.Response( status=400, message=( 'Direct access through ows-grass is blocked. Only' ' non-ows-grass microservice-to-microservice requests' ' are allowed.' ), ) ) return f(*args, **kwargs) return _validate