def public_objectview(request, account, container, prefix=None):
    """ Returns list of all objects in current container. """
    storage_url = settings.STORAGE_URL + account
    auth_token = ' '
    try:
        _meta, objects = client.get_container(
            storage_url, auth_token, container, delimiter='/', prefix=prefix)

    except client.ClientException:
        traceback.print_exc()
        messages.add_message(request, messages.ERROR, _("Access denied."))
        return redirect(containerview)

    prefixes = prefix_list(prefix)
    pseudofolders, objs = pseudofolder_object_list(objects, prefix)
    base_url = get_base_url(request)
    account = storage_url.split('/')[-1]

    return render_to_response("publicview.html", {
        'container': container,
        'objects': objs,
        'folders': pseudofolders,
        'prefix': prefix,
        'prefixes': prefixes,
        'base_url': base_url,
        'storage_url': storage_url,
        'account': account},
        context_instance=RequestContext(request))
Example #2
0
def public_objectview(request, account, container, prefix=None):
    """ Returns list of all objects in current container. """
    storage_url = settings.STORAGE_URL + account
    auth_token = ' '
    try:
        _meta, objects = client.get_container(storage_url,
                                              auth_token,
                                              container,
                                              delimiter='/',
                                              prefix=prefix)

    except client.ClientException:
        messages.add_message(request, messages.ERROR, _("Access denied."))
        return redirect(containerview)

    prefixes = prefix_list(prefix)
    pseudofolders, objs = pseudofolder_object_list(objects, prefix)
    base_url = get_base_url(request)
    account = storage_url.split('/')[-1]

    return render_to_response("publicview.html", {
        'container': container,
        'objects': objs,
        'folders': pseudofolders,
        'prefix': prefix,
        'prefixes': prefixes,
        'base_url': base_url,
        'storage_url': storage_url,
        'account': account
    },
                              context_instance=RequestContext(request))
Example #3
0
def get_segment_number(file_name, request, container, prefix=None):
    '''Return the segment number a given file should create next. If it is 0,
    create a pseudo folder for the file. The folder is created if it doesn't
    exist. '''

    if prefix:
        foldername = prefix + '/' + file_name + '_segments'
    else:
        foldername = file_name + '_segments'

    storage_url = request.session.get('storage_url', '')
    auth_token = request.session.get('auth_token', '')

    foldername = os.path.normpath(foldername)
    foldername = foldername.strip('/')
    foldername += '/'

    content_type = 'application/directory'
    obj = None

    client.put_object(storage_url, auth_token, container, foldername, obj,
                      content_type=content_type)

    meta, objects = client.get_container(storage_url, auth_token, container,
                                         delimiter='/', prefix=foldername)

    pseudofolders, objs = pseudofolder_object_list(objects, prefix)

    return get_first_nonconsecutive(objs)
Example #4
0
def cloudview(request, cloud, prefix=None):
    """ Returns list of all objects in a cloud. """

    storage_url = request.session.get('storage_url', settings.STORAGE_URL)
    auth_token = request.session.get('auth_token', 'demo')
    request.session['cloud'] = getcloud(request)
    objects = []
    read_acl = []
    buckets = cloud_to_bucket(cloud)
    arrayOfBuckets = buckets.split(",")

    newkey = u"{key}".format(key='bucket')
    for bucket in arrayOfBuckets:
        try:
            meta, objects1 = client.get_container(storage_url, auth_token, bucket, delimiter='/', prefix=prefix)
            for entry in objects1:
                value = u"{value}".format( value=bucket)
                entry.update({newkey:value})
            objects += objects1
            read_acl += meta.get('x-container-read', '').split(',')

        except client.ClientException:
            messages.add_message(request, messages.ERROR, _("No Access to Bucket %s." % bucket))

    #merge all buckets

    prefixes = prefix_list(prefix)
    pseudofolders, objs = pseudofolder_object_list(objects, prefix)
    objs.sort(key=lambda x:x['last_modified'],  reverse=True)
    del objs[100:]
    base_url = get_base_url(request)
    account = storage_url.split('/')[-1]
    public = False
    required_acl = ['.r:*', '.rlistings']
    if [x for x in read_acl if x in required_acl]:
        public = True

    return render_to_response("cloudview.html", {
        'container': buckets,
        'cloud': cloud,
        'objects': objs,
        'folders': pseudofolders,
        'session': request.session,
        'prefix': prefix,
        'prefixes': prefixes,
        'base_url': base_url,
        'account': account,
        'public': public},
        context_instance=RequestContext(request))
Example #5
0
def objectview(request, container, prefix=None):
    """ Returns list of all objects in current container. """

    storage_url = request.session.get('storage_url', '')
    auth_token = request.session.get('auth_token', '')
    
    request.session['container'] = container   
    request.session['prefix'] = prefix
           
    try:
        meta, objects = client.get_container(storage_url, auth_token,
                                             container, delimiter='/',
                                             prefix=prefix)

    except client.ClientException:
        messages.add_message(request, messages.ERROR, _("Access denied."))
        return redirect(containerview)

    prefixes = prefix_list(prefix)
    pseudofolders, objs = pseudofolder_object_list(objects, prefix)
    base_url = get_base_url(request)
    account = storage_url.split('/')[-1]

    read_acl = meta.get('x-container-read', '').split(',')
    public = False
    required_acl = ['.r:*', '.rlistings']
    if [x for x in read_acl if x in required_acl]:
        public = True

    return render_to_response("objectview.html", {
        'container': container,
        'objects': objs,
        'folders': pseudofolders,
        'session': request.session,
        'prefix': prefix,
        'prefixes': prefixes,
        'base_url': base_url,
        'account': account,
        'public': public,
        },
        context_instance=RequestContext(request))
Example #6
0
def objectview(request, container, prefix=None):
    """ Returns list of all objects in current container. """

    storage_url = request.session.get('storage_url', '')
    auth_token = request.session.get('auth_token', '')

    try:
        meta, objects = client.get_container(storage_url,
                                             auth_token,
                                             container,
                                             delimiter='/',
                                             prefix=prefix)

    except client.ClientException:
        traceback.print_exc()
        messages.add_message(request, messages.ERROR, _("Access denied."))
        return redirect(containerview)

    prefixes = prefix_list(prefix)
    pseudofolders, objs = pseudofolder_object_list(objects, prefix)
    base_url = get_base_url(request)
    account = storage_url.split('/')[-1]

    read_acl = meta.get('x-container-read', '').split(',')
    public = False
    required_acl = ['.r:*', '.rlistings']
    if [x for x in read_acl if x in required_acl]:
        public = True

    return render_to_response("objectview.html", {
        'container': container,
        'objects': objs,
        'folders': pseudofolders,
        'session': request.session,
        'prefix': prefix,
        'prefixes': prefixes,
        'base_url': base_url,
        'account': account,
        'public': public
    },
                              context_instance=RequestContext(request))
Example #7
0
def create_manifest(request, container, prefix=None):
    '''Given a file name, upload a manifest file assuming the segments are held
    in a "<file_name>_segments" pseudo folder.

    Return an error if the upload of the manifest fails.

    Return an HTTP request with status 201 if no issues.
    '''
    if (request.POST):
        form = StartSloForm(request.POST)
        if form.is_valid():

            # Get objects in the segment folder
            file_name = form.cleaned_data["file_name"]

            if prefix:
                foldername = prefix + '/' + file_name + '_segments'
            else:
                foldername = file_name + '_segments'

            storage_url = request.session.get('storage_url', '')
            auth_token = request.session.get('auth_token', '')

            foldername = os.path.normpath(foldername)
            foldername = foldername.strip('/')
            foldername += '/'

            meta, objects = client.get_container(
                storage_url, auth_token, container + "_segments",
                delimiter='/', prefix=foldername)

            pseudofolders, objs = pseudofolder_object_list(objects, prefix)

            # Create

            manifest = []

            # Create a manifest entry for each segment
            for segment in objs:

                manifest.append({
                    "path": "/" + container + "_segments/" + segment["name"],
                    "etag": segment["hash"].encode('ascii', 'ignore'),
                    "size_bytes": str(segment["bytes"]),
                })

            manifest = sorted(manifest, key=lambda k: k['path'])

            with NamedTemporaryFile() as f:
                json.dump(manifest, f)
                f.seek(0)

                try:

                    #TODO: add prefix to file_name
                    client.put_object(
                        storage_url, auth_token,
                        container.encode('ascii', 'ignore'), file_name, f,
                        query_string="multipart-manifest=put")
                except Exception, e:
                    return HttpResponse("Failed to upload manifest.",
                                        status=500)

            return HttpResponse("Successfully uploaded " + file_name,
                                status=201)
Example #8
0
def objectview(request, container, prefix=None):
    """ Returns list of all objects in current container. """

    storage_url = request.session.get('storage_url', '')
    auth_token = request.session.get('auth_token', '')
    
    key = 'MYKEY'
    request.session['container'] = container   
    request.session['prefix'] = prefix
      
    redirect_url = get_base_url(request)
    redirect_url += reverse('objectview', kwargs={'container': container, })

    swift_url = storage_url + '/' + container + '/'
    if prefix:
        swift_url += prefix
        redirect_url += prefix 

    url_parts = urlparse.urlparse(swift_url)
    path = url_parts.path
           
    try:
        meta, objects = client.get_container(storage_url, auth_token,
                                             container, delimiter='/',
                                             prefix=prefix)
    
    except client.ClientException:
        messages.add_message(request, messages.ERROR, _("Access denied."))
        return redirect(containerview)
    prefixes = prefix_list(prefix)
    pseudofolders, objs = pseudofolder_object_list(objects, prefix)
    base_url = get_base_url(request)
    account = storage_url.split('/')[-1]

    read_acl = meta.get('x-container-read', '').split(',')
    public = False
    required_acl = ['.r:*', '.rlistings']
    
    max_file_size = 5368709122
    max_file_count = 1
    expires = int(time.time() + 15 * 60)
    
    hmac_body = '%s\n%s\n%s\n%s\n%s' % (path, redirect_url,
        max_file_size, max_file_count, expires)
    signature = hmac.new(key, hmac_body, sha1).hexdigest()
   
    if not key:
        messages.add_message(request, messages.ERROR, _("Access denied."))
        if prefix:
            return redirect(objectview, container=container, prefix=prefix)
        else:
            return redirect(objectview, container=container)
            
    if [x for x in read_acl if x in required_acl]:
        public = True

    return render_to_response("objectview.html", {
        'swift_url': swift_url,
        'signature': signature,
        'redirect_url': redirect_url,
        'container': container,
        'objects': objs,
        'folders': pseudofolders,
        'session': request.session,
        'prefix': prefix,
        'prefixes': prefixes,
        'base_url': base_url,
        'account': account,
        'public': public,
        'max_file_size': max_file_size,
        'max_file_count': max_file_count,
        'expires': expires,
        },
        context_instance=RequestContext(request))