Ejemplo n.º 1
0
    def POST(self, req):
        """
        Handles Delete Multiple Objects.
        """
        def object_key_iter(xml):
            dom = parseString(xml)
            delete = dom.getElementsByTagName('Delete')[0]
            for obj in delete.getElementsByTagName('Object'):
                key = obj.getElementsByTagName('Key')[0].firstChild.data
                version = None
                if obj.getElementsByTagName('VersionId').length > 0:
                    version = obj.getElementsByTagName('VersionId')[0]\
                        .firstChild.data
                yield (key, version)

        def get_deleted_elem(key):
            return '  <Deleted>\r\n' \
                   '    <Key>%s</Key>\r\n' \
                   '  </Deleted>\r\n' % (key)

        def get_err_elem(key, err_code, message):
            return '  <Error>\r\n' \
                   '    <Key>%s</Key>\r\n' \
                   '    <Code>%s</Code>\r\n' \
                   '    <Message>%s</Message>\r\n' \
                   '  </Error>\r\n' % (key, err_code, message)

        body = '<?xml version="1.0" encoding="UTF-8"?>\r\n' \
               '<DeleteResult ' \
               'xmlns="http://doc.s3.amazonaws.com/2006-03-01">\r\n'
        for key, version in object_key_iter(req.body):
            if version is not None:
                # TODO: delete the specific version of the object
                return get_err_response('Unsupported')

            sub_req = Request(req.environ.copy())
            sub_req.query_string = ''
            sub_req.content_length = 0
            sub_req.method = 'DELETE'
            controller = ObjectController(sub_req, self.app, self.account_name,
                                          req.environ['HTTP_X_AUTH_TOKEN'],
                                          self.container_name, key)
            sub_resp = controller.DELETE(sub_req)
            status = sub_resp.status_int

            if status == HTTP_NO_CONTENT or status == HTTP_NOT_FOUND:
                body += get_deleted_elem(key)
            else:
                if status == HTTP_UNAUTHORIZED:
                    body += get_err_elem(key, 'AccessDenied', 'Access Denied')
                else:
                    body += get_err_elem(key, 'InvalidURI', 'Invalid URI')

        body += '</DeleteResult>\r\n'
        return HTTPOk(body=body)
Ejemplo n.º 2
0
 def __call__(self, env, start_response):
     req = Request(env)
     try:
         key = req.headers['X-AES-Key']
         aes = AESCipher(key)
         if req.method == 'PUT':
             if req.content_length != None and req.body != None:
                 req.body = aes.encrypt(req.body)
                 req.content_length = len(req.body)
     except Exception:
         self.logger.info('No key provided')
     return self.app(env, start_response)
Ejemplo n.º 3
0
	def __call__(self, env, start_response):
		req = Request(env)
		try:
			key = req.headers['X-AES-Key']
			aes = AESCipher(key)
			if req.method == 'PUT':
				if req.content_length != None and req.body != None:
					req.body = aes.encrypt(req.body)
					req.content_length = len(req.body)
		except Exception:
			self.logger.info('No key provided')
		return self.app(env, start_response)
Ejemplo n.º 4
0
    def _delete_multiple_objects(self, req):
        def _object_key_iter(xml):
            dom = parseString(xml)
            delete = dom.getElementsByTagName('Delete')[0]
            for obj in delete.getElementsByTagName('Object'):
                key = obj.getElementsByTagName('Key')[0].firstChild.data
                version = None
                if obj.getElementsByTagName('VersionId').length > 0:
                    version = obj.getElementsByTagName('VersionId')[0]\
                        .firstChild.data
                yield (key, version)

        def _get_deleted_elem(key):
            return '  <Deleted>\r\n' \
                   '    <Key>%s</Key>\r\n' \
                   '  </Deleted>\r\n' % (key)

        def _get_err_elem(key, err_code, message):
            return '  <Error>\r\n' \
                   '    <Key>%s</Key>\r\n' \
                   '    <Code>%s</Code>\r\n' \
                   '    <Message>%s</Message>\r\n' \
                   '  </Error>\r\n' % (key, err_code, message)

        body = '<?xml version="1.0" encoding="UTF-8"?>\r\n' \
               '<DeleteResult ' \
               'xmlns="http://doc.s3.amazonaws.com/2006-03-01">\r\n'
        for key, version in _object_key_iter(req.body):
            if version is not None:
                # TODO: delete the specific version of the object
                return get_err_response('Unsupported')

            sub_req = Request(req.environ.copy())
            sub_req.query_string = ''
            sub_req.content_length = 0
            sub_req.method = 'DELETE'
            controller = ObjectController(sub_req, self.app, self.account_name,
                                          req.environ['HTTP_X_AUTH_TOKEN'],
                                          self.container_name, key)
            sub_resp = controller.DELETE(sub_req)
            status = sub_resp.status_int

            if status == HTTP_NO_CONTENT or status == HTTP_NOT_FOUND:
                body += _get_deleted_elem(key)
            else:
                if status == HTTP_UNAUTHORIZED:
                    body += _get_err_elem(key, 'AccessDenied', 'Access Denied')
                else:
                    body += _get_err_elem(key, 'InvalidURI', 'Invalid URI')

        body += '</DeleteResult>\r\n'
        return HTTPOk(body=body)