"""Validation utils.""" from functools import wraps from oto import response from oto.adaptors.flask import flaskify from marketing.constants import header def reject_grass_headers(request): """Decorator that rejects grass headers. Returns: callable: the wrapped function. """ def decorator(f): @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 return decorator