Exemplo n.º 1
0
 def delete(self):
     message = _("You are not permitted to delete this tag.")
     raise exception.Forbidden(message)
Exemplo n.º 2
0
 def save(self):
     message = _("You are not permitted to update this tag.")
     raise exception.Forbidden(message)
 def test_download_forbidden(self):
     request = unit_test_utils.get_fake_request()
     self.image_repo.result = exception.Forbidden()
     self.assertRaises(webob.exc.HTTPForbidden, self.controller.download,
                       request, uuidutils.generate_uuid())
Exemplo n.º 4
0
 def fake_enforce(context, action, target):
     raise exception.Forbidden()
Exemplo n.º 5
0
 def data_iterator():
     self.notifier.log = []
     yield 'abcde'
     raise exception.Forbidden('Not allowed')
Exemplo n.º 6
0
 def get_data(*args, **kwargs):
     raise exception.Forbidden()
Exemplo n.º 7
0
 def set_data(self, *args, **kwargs):
     message = _("You are not permitted to upload data for this image.")
     raise exception.Forbidden(message)
Exemplo n.º 8
0
    def _do_request(self, method, url, body, headers):
        """
        Connects to the server and issues a request.  Handles converting
        any returned HTTP error status codes to OpenStack/Glance exceptions
        and closing the server connection. Returns the result data, or
        raises an appropriate exception.

        :param method: HTTP method ("GET", "POST", "PUT", etc...)
        :param url: urlparse.ParsedResult object with URL information
        :param body: data to send (as string, filelike or iterable),
                     or None (default)
        :param headers: mapping of key/value pairs to add as headers

        :note

        If the body param has a read attribute, and method is either
        POST or PUT, this method will automatically conduct a chunked-transfer
        encoding and use the body as a file object or iterable, transferring
        chunks of data using the connection's send() method. This allows large
        objects to be transferred efficiently without buffering the entire
        body in memory.
        """
        if url.query:
            path = url.path + "?" + url.query
        else:
            path = url.path

        try:
            connection_type = self.get_connection_type()
            headers = headers or {}

            if 'x-auth-token' not in headers and self.auth_tok:
                headers['x-auth-token'] = self.auth_tok

            c = connection_type(url.hostname, url.port, **self.connect_kwargs)

            def _pushing(method):
                return method.lower() in ('post', 'put')

            def _simple(body):
                return body is None or isinstance(body, basestring)

            def _filelike(body):
                return hasattr(body, 'read')

            def _sendbody(connection, iter):
                connection.endheaders()
                for sent in iter:
                    # iterator has done the heavy lifting
                    pass

            def _chunkbody(connection, iter):
                connection.putheader('Transfer-Encoding', 'chunked')
                connection.endheaders()
                for chunk in iter:
                    connection.send('%x\r\n%s\r\n' % (len(chunk), chunk))
                connection.send('0\r\n\r\n')

            # Do a simple request or a chunked request, depending
            # on whether the body param is file-like or iterable and
            # the method is PUT or POST
            #
            if not _pushing(method) or _simple(body):
                # Simple request...
                c.request(method, path, body, headers)
            elif _filelike(body) or self._iterable(body):
                c.putrequest(method, path)

                for header, value in headers.items():
                    c.putheader(header, value)

                iter = self.image_iterator(c, headers, body)

                if self._sendable(body):
                    # send actual file without copying into userspace
                    _sendbody(c, iter)
                else:
                    # otherwise iterate and chunk
                    _chunkbody(c, iter)
            else:
                raise TypeError('Unsupported image type: %s' % body.__class__)

            res = c.getresponse()

            def _retry(res):
                return res.getheader('Retry-After')

            status_code = self.get_status_code(res)
            if status_code in self.OK_RESPONSE_CODES:
                return res
            elif status_code in self.REDIRECT_RESPONSE_CODES:
                raise exception.RedirectException(res.getheader('Location'))
            elif status_code == httplib.UNAUTHORIZED:
                raise exception.NotAuthenticated(res.read())
            elif status_code == httplib.FORBIDDEN:
                raise exception.Forbidden(res.read())
            elif status_code == httplib.NOT_FOUND:
                raise exception.NotFound(res.read())
            elif status_code == httplib.CONFLICT:
                raise exception.Duplicate(res.read())
            elif status_code == httplib.BAD_REQUEST:
                raise exception.Invalid(res.read())
            elif status_code == httplib.MULTIPLE_CHOICES:
                raise exception.MultipleChoices(body=res.read())
            elif status_code == httplib.REQUEST_ENTITY_TOO_LARGE:
                raise exception.LimitExceeded(retry=_retry(res),
                                              body=res.read())
            elif status_code == httplib.INTERNAL_SERVER_ERROR:
                raise exception.ServerError(body=res.read())
            elif status_code == httplib.SERVICE_UNAVAILABLE:
                raise exception.ServiceUnavailable(retry=_retry(res))
            else:
                raise exception.UnexpectedStatus(status=status_code,
                                                 body=res.read())

        except (socket.error, IOError), e:
            raise exception.ClientConnectionError(e)
Exemplo n.º 9
0
 def forbidden_key(self, key, *args, **kwargs):
     message = _("You are not permitted to modify '%s' on this image.")
     raise exception.Forbidden(message % key)
Exemplo n.º 10
0
 def forbidden(self, *args, **kwargs):
     message = _("You are not permitted to modify tags on this image.")
     raise exception.Forbidden(message)
Exemplo n.º 11
0
 def add(self, image_member):
     if (self.image.owner == self.context.owner or self.context.is_admin):
         self.member_repo.add(image_member)
     else:
         message = _("You cannot add image member for %s")
         raise exception.Forbidden(message % self.image.image_id)
Exemplo n.º 12
0
def _validate_image_accepts_members(visibility):
    if visibility != 'shared':
        message = _("Only shared images have members.")
        raise exception.Forbidden(message)
 def forbidden(self, *args, **kwargs):
     resource = getattr(self, 'resource_name', 'resource')
     message = _("You are not permitted to modify '%(attr)s' on this "
                 "%(resource)s.")
     raise exception.Forbidden(message % {'attr': attr,
                                          'resource': resource})
Exemplo n.º 14
0
 def get_image(self, image_id):
     raise glance_exception.Forbidden()
Exemplo n.º 15
0
 def reactivate(self, *args, **kwargs):
     message = _("You are not permitted to reactivate this image.")
     raise exception.Forbidden(message)
Exemplo n.º 16
0
 def get_data():
     raise exception.Forbidden()
Exemplo n.º 17
0
 def begin_processing(self):
     message = _("You are not permitted to set status on this task.")
     raise exception.Forbidden(message)
    def test_catch_error_forbidden(self, mock_function):
        mock_function.side_effect = exception.Forbidden()

        self.assertEqual(cache_manage.FAILURE,
                         cache_manage.list_cached(mock.Mock(), None))
Exemplo n.º 19
0
 def succeed(self, result):
     message = _("You are not permitted to set status on this task.")
     raise exception.Forbidden(message)
Exemplo n.º 20
0
 def __len__(self):
     raise exception.Forbidden()
Exemplo n.º 21
0
 def fail(self, message):
     message = _("You are not permitted to set status on this task.")
     raise exception.Forbidden(message)
Exemplo n.º 22
0
 def disk_format(self, value):
     if hasattr(self, '_disk_format') and self.status != 'queued':
         msg = _("Attribute disk_format can be only replaced "
                 "for a queued image.")
         raise exception.Forbidden(message=msg)
     self._disk_format = value
Exemplo n.º 23
0
 def delete(self):
     message = _("You are not permitted to delete this meta_resource_type.")
     raise exception.Forbidden(message)
Exemplo n.º 24
0
 def enforce(self, _ctxt, action, target=None, **kwargs):
     """Raise Forbidden if a rule for given action is set to false."""
     if self.rules.get(action) is False:
         raise exception.Forbidden()
Exemplo n.º 25
0
 def fake_get(self):
     raise exception.Forbidden()