Пример #1
0
    def _merge_account(self, src_account, dest_account, delete_src=False):
            # TODO: handle exceptions
            # copy all source objects
            for path in self.list_all_objects(src_account):
                src_container, src_name = split_container_object_string(
                    '/%s' % path)

                # give read permissions to the dest_account
                permissions = self.backend.get_object_permissions(
                    src_account, src_account, src_container, src_name)
                if permissions:
                    permissions = permissions[2]
                permissions['read'] = permissions.get('read', [])
                permissions['read'].append(dest_account)
                self.backend.update_object_permissions(src_account,
                                                       src_account,
                                                       src_container,
                                                       src_name,
                                                       permissions)

                self._copy_object(src_account, src_container, src_name,
                                 dest_account, move=delete_src)

            # move groups also
            groups = self.backend.get_account_groups(src_account, src_account)
            (v.replace(src_account, dest_account) for v in groups.values())
            self.backend.update_account_groups(dest_account, dest_account,
                                               groups)
            if delete_src:
                self._delete_account(src_account)
Пример #2
0
    def _merge_account(self, src_account, dest_account, delete_src=False):
        # TODO: handle exceptions
        # copy all source objects
        for path in self._list_all_objects(src_account):
            src_container, src_name = split_container_object_string('/%s' %
                                                                    path)

            # give read permissions to the dest_account
            permissions = self.backend.get_object_permissions(
                src_account, src_account, src_container, src_name)
            if permissions:
                permissions = permissions[2]
            permissions['read'] = permissions.get('read', [])
            permissions['read'].append(dest_account)
            self.backend.update_object_permissions(src_account, src_account,
                                                   src_container, src_name,
                                                   permissions)

            self._copy_object(src_account,
                              src_container,
                              src_name,
                              dest_account,
                              move=delete_src)

        # move groups also
        groups = self.backend.get_account_groups(src_account, src_account)
        (v.replace(src_account, dest_account) for v in groups.values())
        self.backend.update_account_groups(dest_account, dest_account, groups)
        if delete_src:
            self._delete_account(src_account)
Пример #3
0
def public_read(request, v_public):
    # Normal Response Codes: 200, 206
    # Error Response Codes: internalServerError (500),
    #                       rangeNotSatisfiable (416),
    #                       preconditionFailed (412),
    #                       itemNotFound (404),
    #                       badRequest (400),
    #                       notModified (304)

    request.user_uniq = None
    try:
        v_account, v_container, v_object = request.backend.get_public(request.user_uniq, v_public)
        meta = request.backend.get_object_meta(request.user_uniq, v_account, v_container, v_object, "pithos")
        public = request.backend.get_object_public(request.user_uniq, v_account, v_container, v_object)
    except:
        raise faults.ItemNotFound("Object does not exist")

    if not public:
        raise faults.ItemNotFound("Object does not exist")
    update_manifest_meta(request, v_account, meta)

    # Evaluate conditions.
    validate_modification_preconditions(request, meta)
    try:
        validate_matching_preconditions(request, meta)
    except faults.NotModified:
        response = HttpResponse(status=304)
        response["ETag"] = meta["hash"] if not UPDATE_MD5 else meta["checksum"]
        return response

    sizes = []
    hashmaps = []
    if "X-Object-Manifest" in meta:
        try:
            src_container, src_name = split_container_object_string("/" + meta["X-Object-Manifest"])
            objects = request.backend.list_objects(
                request.user_uniq, v_account, src_container, prefix=src_name, virtual=False
            )
        except:
            raise faults.ItemNotFound("Object does not exist")

        try:
            for x in objects:
                _, s, h = request.backend.get_object_hashmap(request.user_uniq, v_account, src_container, x[0], x[1])
                sizes.append(s)
                hashmaps.append(h)
        except:
            raise faults.ItemNotFound("Object does not exist")
    else:
        try:
            _, s, h = request.backend.get_object_hashmap(request.user_uniq, v_account, v_container, v_object)
            sizes.append(s)
            hashmaps.append(h)
        except:
            raise faults.ItemNotFound("Object does not exist")
    return object_data_response(request, sizes, hashmaps, meta, True)
Пример #4
0
def public_read(request, v_public):
    # Normal Response Codes: 200, 206
    # Error Response Codes: internalServerError (500),
    #                       rangeNotSatisfiable (416),
    #                       preconditionFailed (412),
    #                       itemNotFound (404),
    #                       badRequest (400),
    #                       notModified (304)

    request.user_uniq = None
    try:
        v_account, v_container, v_object = request.backend.get_public(
            request.user_uniq,
            v_public)
        meta = request.backend.get_object_meta(request.user_uniq, v_account,
                                               v_container, v_object, 'pithos')
        public = request.backend.get_object_public(
            request.user_uniq, v_account,
            v_container, v_object)
    except:
        raise faults.ItemNotFound('Object does not exist')

    if not public:
        raise faults.ItemNotFound('Object does not exist')
    update_manifest_meta(request, v_account, meta)

    # Evaluate conditions.
    validate_modification_preconditions(request, meta)
    try:
        validate_matching_preconditions(request, meta)
    except faults.NotModified:
        response = HttpResponse(status=304)
        response['ETag'] = meta['hash'] if not UPDATE_MD5 else meta['checksum']
        return response

    sizes = []
    hashmaps = []
    if 'X-Object-Manifest' in meta:
        try:
            src_container, src_name = split_container_object_string(
                '/' + meta['X-Object-Manifest'])
            objects = request.backend.list_objects(
                request.user_uniq, v_account,
                src_container, prefix=src_name, virtual=False)
        except:
            raise faults.ItemNotFound('Object does not exist')

        try:
            for x in objects:
                _, s, h = request.backend.get_object_hashmap(request.user_uniq,
                                                             v_account,
                                                             src_container,
                                                             x[0], x[1])
                sizes.append(s)
                hashmaps.append(h)
        except:
            raise faults.ItemNotFound('Object does not exist')
    else:
        try:
            _, s, h = request.backend.get_object_hashmap(
                request.user_uniq, v_account,
                v_container, v_object)
            sizes.append(s)
            hashmaps.append(h)
        except:
            raise faults.ItemNotFound('Object does not exist')
    return object_data_response(request, sizes, hashmaps, meta, True)
Пример #5
0
def public_read(request, v_public):
    # Normal Response Codes: 200, 206
    # Error Response Codes: internalServerError (500),
    #                       rangeNotSatisfiable (416),
    #                       preconditionFailed (412),
    #                       itemNotFound (404),
    #                       badRequest (400),
    #                       notModified (304)

    request.user_uniq = None
    try:
        v_account, v_container, v_object = request.backend.get_public(
            request.user_uniq,
            v_public)
        meta = request.backend.get_object_meta(request.user_uniq, v_account,
                                               v_container, v_object, 'pithos')
        public = request.backend.get_object_public(
            request.user_uniq, v_account,
            v_container, v_object)
    except:
        raise faults.ItemNotFound('Object does not exist')

    if not public:
        raise faults.ItemNotFound('Object does not exist')
    update_manifest_meta(request, v_account, meta)

    # Evaluate conditions.
    validate_modification_preconditions(request, meta)
    try:
        validate_matching_preconditions(request, meta)
    except faults.NotModified:
        response = HttpResponse(status=304)
        response['ETag'] = meta['ETag']
        return response

    sizes = []
    hashmaps = []
    if 'X-Object-Manifest' in meta:
        try:
            src_container, src_name = split_container_object_string(
                '/' + meta['X-Object-Manifest'])
            objects = request.backend.list_objects(
                request.user_uniq, v_account,
                src_container, prefix=src_name, virtual=False)
        except:
            raise faults.ItemNotFound('Object does not exist')

        try:
            for x in objects:
                s, h = request.backend.get_object_hashmap(request.user_uniq,
                                                          v_account,
                                                          src_container,
                                                          x[0], x[1])
                sizes.append(s)
                hashmaps.append(h)
        except:
            raise faults.ItemNotFound('Object does not exist')
    else:
        try:
            s, h = request.backend.get_object_hashmap(
                request.user_uniq, v_account,
                v_container, v_object)
            sizes.append(s)
            hashmaps.append(h)
        except:
            raise faults.ItemNotFound('Object does not exist')

    if 'Content-Disposition' not in meta:
        name = v_object.rstrip('/').split('/')[-1]
        if not name:
            name = v_public
        meta['Content-Disposition'] = 'attachment; filename=%s' % (name,)

    return object_data_response(request, sizes, hashmaps, meta, True)