예제 #1
0
파일: types.py 프로젝트: sainusahib/cyborg
 def validate(value):
     try:
         jsonutils.dumps(value)
     except TypeError:
         raise exception.InvalidJsonType(value=value)
     else:
         return value
예제 #2
0
    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)