def __call__(self, env, start_response):
        request = Request(env)
        try:
            (version, account, container, objname) = split_path(request.path_info, 1, 4, True)
        except ValueError:
            response = request.get_response(self.app)
            return response(env, start_response)
        if not objname:
            response = request.get_response(self.app)
            if container:
                if not request.params.has_key('compress'):
                    response.body = response.body.replace(self.compress_suffix, '')
            return response(env, start_response)

        original_path_info = request.path_info
        request.path_info += self.compress_suffix
        if request.method == 'GET':
            if not request.params.has_key('compress'):
                # we need to decompress
                response = request.get_response(self.app)

                if response.status_int == 404:
                    # it may not be compressed, if admin added the compress filter after 
                    # some files have been uploaded
                    request.path_info = original_path_info
                    response = request.get_response(self.app)
                    return response(env, start_response)
                uncompressed_data = create_uncompress(response.body)
                response.body = uncompressed_data
                return response(env, start_response)
       
        if request.method == 'PUT':
            if hasattr(request, 'body_file'):
                data = ""
                while True:
                    chunk = request.body_file.read()
                    if not chunk:
                        break
                    data += chunk
                request.body = data
                compress_data = create_compress(data)
            else:
                compress_data = create_compress(request.body)
            if compress_data:
                request.body = compress_data

        response = request.get_response(self.app)
        return response(env, start_response)
	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)
Пример #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)
Пример #4
0
    def completeMultipartUpload(self, env, start_response):
        req = Request(env)
        if 'QUERY_STRING' in env:
            args = dict(urlparse.parse_qsl(env['QUERY_STRING'], 1))
        else:
            args = {}

        uploadId = args['uploadId']

        urlparts = urlparse.urlparse(req.url)
        version, auth, ignored = split_path(urlparts.path, 2, 3, True)

        # We must get the actual container/object info from the RAW_PATH_INFO
        path = env['RAW_PATH_INFO']
        container, obj = split_path(path, 0, 2, True)
        if obj is None:
            obj = os.path.basename(env['RAW_PATH_INFO'])

        #
        # Query for the objects in the segments area to make sure it completed
        #
        env['REQUEST_METHOD'] = 'GET'
        env['PATH_INFO'] = ('/%s/%s/%s_segments' % (version, auth, container))
        env['RAW_PATH_INFO'] = ('/%s/%s/%s_segments' % (version, auth,
                                                        container))
        env['QUERY_STRING'] = 'format=json&limit=1001&prefix=%s/%s/' \
                              '&delimiter=/' % (obj, uploadId)
        env['SCRIPT_NAME'] = ''

        req = Request(env)

        body_iter = self._app_call(env)
        status = self._get_status_int()

        objinfo = loads(''.join(list(body_iter)))

        if len(objinfo) == 0:
            return get_err_response('NoSuchBucket')

        #
        # Tell Swift the manifest info
        # The content length should be 0 and the manifest should point to
        # the segment container.
        #
        req.method = 'PUT'
        req.headers['X-Object-Manifest'] = ('%s_segments/%s/%s' % (container,
                                            obj, uploadId))
        req.headers['Content-Length'] = '0'
        env['PATH_INFO'] = ('/%s/%s/%s/%s' % (version, auth, container, obj))
        env['RAW_PATH_INFO'] = ('/%s/%s/%s/%s' %
                                (version, auth, container, obj))
        del env['QUERY_STRING']
        env['SCRIPT_NAME'] = ''
        req.body = ''

        body_iter = self._app_call(env)
        status = self._get_status_int()

        if status != HTTP_OK and status != HTTP_CREATED:
            if status == HTTP_UNAUTHORIZED:
                return get_err_response('AccessDenied')
            elif status == HTTP_NOT_FOUND:
                return get_err_response('NoSuchBucket')
            else:
                return get_err_response('InvalidURI')

        o = objinfo[0]

        body = ('<?xml version="1.0" encoding="UTF-8"?>'
                '<CompleteMultipartUploadResult '
                'xmlns="http://s3.amazonaws.com/doc/2006-03-01">'
                '<Location>%s://%s/%s/%s</Location>'
                '<Bucket>%s</Bucket>'
                '<Key>%s</Key>'
                '<ETag>"%s"</ETag>'
                '</CompleteMultipartUploadResult>' %
                (urlparts.scheme, urlparts.netloc, container, obj, container,
                 o['name'], o['hash']))

        resp = Response(body=body, content_type="application/xml")

        return resp
Пример #5
0
    def completeMultipartUpload(self, env, start_response):
        req = Request(env)
        if "QUERY_STRING" in env:
            args = dict(urlparse.parse_qsl(env["QUERY_STRING"], 1))
        else:
            args = {}

        uploadId = args["uploadId"]

        parts = urlparse.urlparse(req.url)
        version, auth, container, obj = split_path(parts.path, 0, 4, True)

        if obj is None:
            obj = os.path.basename(env["RAW_PATH_INFO"])

        #
        # Query for the objects in the segments area to make sure it completed
        #
        env["REQUEST_METHOD"] = "GET"
        env["PATH_INFO"] = "/%s/%s/%s_segments" % (version, auth, container)
        env["RAW_PATH_INFO"] = "/%s/%s/%s_segments" % (version, auth, container)
        env["QUERY_STRING"] = "format=json&limit=1001&prefix=%s/%s/" "&delimiter=/" % (obj, uploadId)
        env["SCRIPT_NAME"] = ""

        req = Request(env)

        body_iter = self._app_call(env)
        status = self._get_status_int()

        objinfo = loads("".join(list(body_iter)))

        if len(objinfo) == 0:
            return get_err_response("NoSuchBucket")

        #
        # Tell Swift the manifest info
        # The content length should be 0 and the manifest should point to
        # the segment container.
        #
        req.method = "PUT"
        req.headers["X-Object-Manifest"] = "%s_segments/%s/%s" % (container, obj, uploadId)
        req.headers["Content-Length"] = "0"
        env["PATH_INFO"] = "/%s/%s/%s/%s" % (version, auth, container, obj)
        env["RAW_PATH_INFO"] = "/%s/%s/%s/%s" % (version, auth, container, obj)
        del env["QUERY_STRING"]
        env["SCRIPT_NAME"] = ""
        req.body = ""

        body_iter = self._app_call(env)
        status = self._get_status_int()

        if status != HTTP_OK and status != HTTP_CREATED:
            if status == HTTP_UNAUTHORIZED:
                return get_err_response("AccessDenied")
            elif status == HTTP_NOT_FOUND:
                return get_err_response("NoSuchBucket")
            else:
                return get_err_response("InvalidURI")

        o = objinfo[0]

        body = (
            '<?xml version="1.0" encoding="UTF-8"?>'
            "<CompleteMultipartUploadResult "
            'xmlns="http://s3.amazonaws.com/doc/2006-03-01">'
            "<Location>%s://%s/%s/%s</Location>"
            "<Bucket>%s</Bucket>"
            "<Key>%s</Key>"
            '<ETag>"%s"</ETag>'
            "</CompleteMultipartUploadResult>"
            % (parts.scheme, parts.netloc, container, obj, container, o["name"], o["hash"])
        )

        resp = Response(body=body, content_type="application/xml")
        return resp
Пример #6
0
    def completeMultipartUpload(self, env, start_response):
        req = Request(env)
        if 'QUERY_STRING' in env:
            args = dict(urlparse.parse_qsl(env['QUERY_STRING'], 1))
        else:
            args = {}

        uploadId = args['uploadId']

        parts = urlparse.urlparse(req.url)
        version, auth, container, obj = split_path(parts.path, 0, 4, True)

        if obj is None:
            obj = os.path.basename(env['RAW_PATH_INFO'])

        #
        # Query for the objects in the segments area to make sure it completed
        #
        env['REQUEST_METHOD'] = 'GET'
        env['PATH_INFO'] = ('/%s/%s/%s_segments' % (version, auth, container))
        env['RAW_PATH_INFO'] = ('/%s/%s/%s_segments' %
                                (version, auth, container))
        env['QUERY_STRING'] = 'format=json&limit=1001&prefix=%s/%s/' \
                              '&delimiter=/' % (obj, uploadId)
        env['SCRIPT_NAME'] = ''

        req = Request(env)

        body_iter = self._app_call(env)
        status = self._get_status_int()

        objinfo = loads(''.join(list(body_iter)))

        if len(objinfo) == 0:
            return get_err_response('NoSuchBucket')

        #
        # Tell Swift the manifest info
        # The content length should be 0 and the manifest should point to
        # the segment container.
        #
        req.method = 'PUT'
        req.headers['X-Object-Manifest'] = ('%s_segments/%s/%s' %
                                            (container, obj, uploadId))
        req.headers['Content-Length'] = '0'
        env['PATH_INFO'] = ('/%s/%s/%s/%s' % (version, auth, container, obj))
        env['RAW_PATH_INFO'] = ('/%s/%s/%s/%s' %
                                (version, auth, container, obj))
        del env['QUERY_STRING']
        env['SCRIPT_NAME'] = ''
        req.body = ''

        body_iter = self._app_call(env)
        status = self._get_status_int()

        if status != HTTP_OK and status != HTTP_CREATED:
            if status == HTTP_UNAUTHORIZED:
                return get_err_response('AccessDenied')
            elif status == HTTP_NOT_FOUND:
                return get_err_response('NoSuchBucket')
            else:
                return get_err_response('InvalidURI')

        o = objinfo[0]

        body = ('<?xml version="1.0" encoding="UTF-8"?>'
                '<CompleteMultipartUploadResult '
                'xmlns="http://s3.amazonaws.com/doc/2006-03-01">'
                '<Location>%s://%s/%s/%s</Location>'
                '<Bucket>%s</Bucket>'
                '<Key>%s</Key>'
                '<ETag>"%s"</ETag>'
                '</CompleteMultipartUploadResult>' %
                (parts.scheme, parts.netloc, container, obj, container,
                 o['name'], o['hash']))

        resp = Response(body=body, content_type="application/xml")
        return resp