Пример #1
0
def validate_issue_token_auth(auth=None):
    if auth is None:
        return
    validation.lazy_validate(schema.token_issue, auth)

    user = auth['identity'].get('password', {}).get('user')
    if user is not None:
        if 'id' not in user and 'name' not in user:
            msg = _('Invalid input for field identity/password/user: '******'id or name must be present.')
            raise exception.SchemaValidationError(detail=msg)

        domain = user.get('domain')
        if domain is not None:
            if 'id' not in domain and 'name' not in domain:
                msg = _(
                    'Invalid input for field identity/password/user/domain: '
                    'id or name must be present.')
                raise exception.SchemaValidationError(detail=msg)

    scope = auth.get('scope')
    if scope is not None and isinstance(scope, dict):
        project = scope.get('project')
        if project is not None:
            if 'id' not in project and 'name' not in project:
                msg = _(
                    'Invalid input for field scope/project: '
                    'id or name must be present.')
                raise exception.SchemaValidationError(detail=msg)
            domain = project.get('domain')
            if domain is not None:
                if 'id' not in domain and 'name' not in domain:
                    msg = _(
                        'Invalid input for field scope/project/domain: '
                        'id or name must be present.')
                    raise exception.SchemaValidationError(detail=msg)
        domain = scope.get('domain')
        if domain is not None:
            if 'id' not in domain and 'name' not in domain:
                msg = _(
                    'Invalid input for field scope/domain: '
                    'id or name must be present.')
                raise exception.SchemaValidationError(detail=msg)
Пример #2
0
 def validate(self, *args, **kwargs):
     try:
         self.validator.validate(*args, **kwargs)
     except jsonschema.ValidationError as ex:
         # NOTE: For whole OpenStack message consistency, this error
         # message has been written in a format consistent with WSME.
         if ex.path:
             # NOTE(lbragstad): Here we could think about using iter_errors
             # as a method of providing invalid parameters back to the
             # user.
             # TODO(lbragstad): If the value of a field is confidential or
             # too long, then we should build the masking in here so that
             # we don't expose sensitive user information in the event it
             # fails validation.
             path = '/'.join(map(six.text_type, ex.path))
             detail = _("Invalid input for field '%(path)s': "
                        "%(message)s") % {'path': path,
                                          'message': six.text_type(ex)}
         else:
             detail = six.text_type(ex)
         raise exception.SchemaValidationError(detail=detail)
Пример #3
0
 def validate(self, *args, **kwargs):
     try:
         self.validator.validate(*args, **kwargs)
     except jsonschema.ValidationError as ex:
         # NOTE: For whole OpenStack message consistency, this error
         # message has been written in a format consistent with WSME.
         if len(ex.path) > 0:
             # NOTE(lbragstad): Here we could think about using iter_errors
             # as a method of providing invalid parameters back to the
             # user.
             # TODO(lbragstad): If the value of a field is confidential or
             # too long, then we should build the masking in here so that
             # we don't expose sensitive user information in the event it
             # fails validation.
             detail = _("Invalid input for field '%(path)s'. The value is "
                        "'%(value)s'.") % {
                            'path': ex.path.pop(),
                            'value': ex.instance
                        }
         else:
             detail = ex.message
         raise exception.SchemaValidationError(detail=detail)