Пример #1
0
def run(args):
    """Download a chunk of data from a file"""

    uid = str(args["uid"])
    drive_uid = str(args["drive_uid"])
    file_uid = str(args["file_uid"])
    chunk_idx = int(args["chunk_index"])
    secret = str(args["secret"])

    drive = DriveInfo(drive_uid=drive_uid)

    try:
        (data, meta, num_chunks) = drive.download_chunk(file_uid=file_uid,
                                                        downloader_uid=uid,
                                                        chunk_index=chunk_idx,
                                                        secret=secret)
    except IndexError:
        data = None
        meta = None
        num_chunks = None

    response = {}

    if data is not None:
        response["chunk"] = bytes_to_string(data)
        data = None

    if meta is not None:
        response["meta"] = json.dumps(meta)

    if num_chunks is not None:
        response["num_chunks"] = int(num_chunks)

    return response
Пример #2
0
def run(args):
    """This file is used to return a list of versions of the
       specified filenames
    """

    drive_uid = str(args["drive_uid"])
    authorisation = Authorisation.from_data(args["authorisation"])
    filename = args["filename"]

    try:
        include_metadata = args["include_metadata"]
    except:
        include_metadata = False

    if include_metadata:
        include_metadata = True
    else:
        include_metadata = False

    drive = DriveInfo(drive_uid=drive_uid)

    versions = drive.list_versions(authorisation=authorisation,
                                   filename=filename,
                                   include_metadata=include_metadata)

    return_value = {}

    return_value["versions"] = list_to_string(versions)

    return return_value
Пример #3
0
def run(args):
    """Close the uploader for a file - this stops new chunks being uploaded"""

    drive_uid = str(args["drive_uid"])
    file_uid = str(args["file_uid"])
    secret = str(args["secret"])

    drive = DriveInfo(drive_uid=drive_uid)

    drive.close_uploader(file_uid=file_uid, secret=secret)

    return True
Пример #4
0
def run(args):
    """Open and return a new ChunkUploader that can be used
       to upload a file in lots of chunks
    """

    filename = str(args["filename"])
    drive_uid = str(args["drive_uid"])

    try:
        aclrules = ACLRules.from_data(args["aclrules"])
    except:
        aclrules = None

    try:
        authorisation = Authorisation.from_data(args["authorisation"])
    except:
        authorisation = None

    try:
        par_uid = str(args["par_uid"])
    except:
        par_uid = None

    try:
        secret = str(args["secret"])
    except:
        secret = None

    try:
        pubkey = PublicKey.from_data(args["encryption_key"])
    except:
        pubkey = None

    if par_uid is not None:
        registry = PARRegistry()
        (par, identifiers) = registry.load(par_uid=par_uid, secret=secret)
    else:
        par = None
        identifiers = None

    drive = DriveInfo(drive_uid=drive_uid)

    (filemeta, uploader) = drive.open_uploader(filename=filename,
                                               aclrules=aclrules,
                                               authorisation=authorisation,
                                               par=par,
                                               identifiers=identifiers)

    return {
        "filemeta": filemeta.to_data(),
        "uploader": uploader.to_data(pubkey=pubkey)
    }
Пример #5
0
def run(args):
    """Close the downloader for a file - this stops new chunks
       being downloaded using this object
    """

    uid = str(args["uid"])
    drive_uid = str(args["drive_uid"])
    file_uid = str(args["file_uid"])
    secret = str(args["secret"])

    drive = DriveInfo(drive_uid=drive_uid)

    drive.close_downloader(file_uid=file_uid,
                           downloader_uid=uid,
                           secret=secret)

    return True
Пример #6
0
def run(args):
    """Upload a new chunk of data to a file"""

    drive_uid = str(args["drive_uid"])
    file_uid = str(args["file_uid"])
    chunk_idx = int(args["chunk_index"])
    secret = str(args["secret"])
    data = string_to_bytes(args["data"])
    checksum = str(args["checksum"])

    drive = DriveInfo(drive_uid=drive_uid)

    drive.upload_chunk(file_uid=file_uid,
                       chunk_index=chunk_idx,
                       secret=secret,
                       chunk=data,
                       checksum=checksum)

    return True
Пример #7
0
def run(args):
    """Call this function to initiate the two-step file-upload process.

       Step 1: upload - tells the service that a file of specific
               size and checksum will be uploaded. This gives the service
               the chance to decide whether this will be allowed. If the
               file is small, and was thus included in the FileHandle,
               then it is uploaded immediately and the operation completes.
               If the file is large, then we now returns a OSPar
               that can be used for this upload (Step 2)

       Step 2: after the user has used the OSPar to upload
               the file, they should call OSPar.close() to notify
               the service that the file has been successfully uploaded.
               This will verify that the file has been uploaded correctly,
               will receipt the storage cost and will delete the OSPar
    """

    filehandle = FileHandle.from_data(args["filehandle"])

    try:
        authorisation = Authorisation.from_data(args["authorisation"])
    except:
        authorisation = None

    try:
        par_uid = args["par_uid"]
    except:
        par_uid = None

    try:
        secret = args["secret"]
    except:
        secret = None

    try:
        public_key = PublicKey.from_data(args["encryption_key"])
    except:
        public_key = None

    if par_uid is not None:
        registry = PARRegistry()
        (par, identifiers) = registry.load(par_uid=par_uid, secret=secret)
    else:
        par = None
        identifiers = None

    drive_uid = filehandle.drive_uid()

    drive = DriveInfo(drive_uid=drive_uid)

    return_value = {}

    (filemeta, par) = drive.upload(filehandle=filehandle,
                                   authorisation=authorisation,
                                   encrypt_key=public_key,
                                   par=par,
                                   identifiers=identifiers)

    if filemeta is not None:
        return_value["filemeta"] = filemeta.to_data()

    if par is not None:
        return_value["upload_par"] = par.to_data()

    return return_value
Пример #8
0
def run(args):
    """This file is used to return a list of the FileMeta objects of files
       that are in a specified drive
    """

    drive_uid = str(args["drive_uid"])

    try:
        authorisation = Authorisation.from_data(args["authorisation"])
    except:
        authorisation = None

    try:
        par_uid = args["par_uid"]
    except:
        par_uid = None

    try:
        secret = args["secret"]
    except:
        secret = None

    try:
        directory = str(args["dir"])
    except:
        directory = None

    try:
        filename = str(args["filename"])
    except:
        filename = None

    try:
        include_metadata = args["include_metadata"]
    except:
        include_metadata = False

    if include_metadata:
        include_metadata = True
    else:
        include_metadata = False

    if par_uid is not None:
        registry = PARRegistry()
        (par, identifiers) = registry.load(par_uid=par_uid, secret=secret)
    else:
        par = None
        identifiers = None

    drive = DriveInfo(drive_uid=drive_uid)

    files = drive.list_files(authorisation=authorisation,
                             include_metadata=include_metadata,
                             par=par,
                             identifiers=identifiers,
                             dir=directory,
                             filename=filename)

    return_value = {}

    return_value["files"] = list_to_string(files)

    return return_value
Пример #9
0
def run(args):
    """Call this function to initiate the two-step file-download process.

       Step 1: download - tells the service to download the file. If the
               file is small then the file will be in the response.
               Otherwise a OSPar will be returned that will let you
               download the file. If this is the case, then you must
               call step 2...

       Step 2: downloaded - after you have downloaded the file from the OSPar
               call OSPar.close() so that the service knows that the OSPar
               is no longer needed and can be deleted
    """

    drive_uid = args["drive_uid"]
    filename = args["filename"]

    try:
        authorisation = Authorisation.from_data(args["authorisation"])
    except:
        authorisation = None

    try:
        par_uid = args["par_uid"]
    except:
        par_uid = None

    try:
        secret = args["secret"]
    except:
        secret = None

    public_key = PublicKey.from_data(args["encryption_key"])

    if "version" in args:
        version = str(args["version"])
    else:
        version = None

    if "force_par" in args:
        force_par = args["force_par"]
    else:
        force_par = None

    if "must_chunk" in args:
        must_chunk = args["must_chunk"]
    else:
        must_chunk = False

    if must_chunk:
        must_chunk = True

    if force_par:
        force_par = True

    if par_uid is not None:
        registry = PARRegistry()
        (par, identifiers) = registry.load(par_uid=par_uid, secret=secret)
    else:
        par = None
        identifiers = None

    drive = DriveInfo(drive_uid=drive_uid)

    return_value = {}

    (filemeta, filedata, par,
     downloader) = drive.download(filename=filename,
                                  version=version,
                                  authorisation=authorisation,
                                  encrypt_key=public_key,
                                  force_par=force_par,
                                  must_chunk=must_chunk,
                                  par=par,
                                  identifiers=identifiers)

    if filemeta is not None:
        return_value["filemeta"] = filemeta.to_data()

    if filedata is not None:
        from Acquire.ObjectStore import bytes_to_string as _bytes_to_string
        return_value["filedata"] = _bytes_to_string(filedata)

    if par is not None:
        return_value["download_par"] = par.to_data()

    if downloader is not None:
        return_value["downloader"] = downloader.to_data(pubkey=public_key)

    return return_value