Пример #1
0
def download_share(request, cid, secret):
    '''download a custom share for a container
    '''
    container = get_container(cid)
    import pickle
    pickle.dump({'cid': cid, 'secret': secret}, open('days.pkl', 'wb'))

    # Is the container secret valid?
    try:
        share = Share.objects.get(secret=secret, container=container)
    except Share.DoesNotExist:
        raise Http404

    # If the share exists, ensure active
    if validate_share(share) is False:
        share.delete()
        raise Response(status.HTTP_403_FORBIDDEN)

    # Now validate the secret
    if secret != share.secret:
        raise Response(status.HTTP_401_UNAUTHORIZED)

    # If we make it here, link is good
    filename = container.get_download_name()
    response = HttpResponse(container.image.datafile.file,
                            content_type='application/img')
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    return response
Пример #2
0
def download_share(request, cid, secret):
    """download a custom share for a container"""
    container = get_container(cid)

    # Is the container secret valid?
    try:
        share = Share.objects.get(secret=secret, container=container)
    except Share.DoesNotExist:
        raise Http404

    # If the share exists, ensure active
    if validate_share(share) is False:
        share.delete()
        raise Response(status.HTTP_403_FORBIDDEN)

    # Now validate the secret
    if secret != share.secret:
        raise Response(status.HTTP_401_UNAUTHORIZED)

    return _download_container(container, request)
Пример #3
0
def download_share(request,cid,secret):
    '''download a custom share for a container
    '''
    container = get_container(cid)
    import pickle
    pickle.dump({'cid':cid,'secret':secret},open('days.pkl','wb'))

    # Is the container secret valid?
    try:
        share = Share.objects.get(secret=secret,
                                  container=container)
    except Share.DoesNotExist:
        raise Http404

    # If the share exists, ensure active
    if validate_share(share) is False:
        share.delete()
        raise Response(status.HTTP_403_FORBIDDEN)

    # Now validate the secret
    if secret != share.secret:
        raise Response(status.HTTP_401_UNAUTHORIZED)

    return _download_container(container)