def validate(value): try: jsonutils.dumps(value) except TypeError: raise exception.InvalidJsonType(value=value) else: return value
def before(self, state): req = state.request service_catalog = None if req.headers.get('X_SERVICE_CATALOG') is not None: try: catalog_header = req.headers.get('X_SERVICE_CATALOG') service_catalog = jsonutils.loads(catalog_header) except ValueError: raise exception.InvalidJsonType('service catalog') # NOTE(jamielennox): This is a full auth plugin set by auth_token # middleware in newer versions. user_auth_plugin = req.environ.get('keystone.token_auth') roles = req.headers.get('X-Roles', '').split(',') is_admin = ('admin' in roles or 'administrator' in roles) state.request.context = context.RequestContext.from_environ( req.environ, user_auth_plugin=user_auth_plugin, is_admin=is_admin, service_catalog=service_catalog)