Ejemplo n.º 1
0
def public_meta(request, v_public):
    # Normal Response Codes: 204
    # Error Response Codes: internalServerError (500),
    #                       itemNotFound (404),
    #                       badRequest (400)

    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)

    response = HttpResponse(status=200)
    put_object_headers(response, meta, True)
    return response
Ejemplo n.º 2
0
def public_meta(request, v_public):
    # Normal Response Codes: 204
    # Error Response Codes: internalServerError (500),
    #                       itemNotFound (404),
    #                       badRequest (400)

    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)

    response = HttpResponse(status=200)
    put_object_headers(response, meta, True)
    return response
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)