示例#1
0
def start_transfer(tid):
    url_path = "/transfers/{tid}/start".format(tid=tid)
    signature = security.sign_path(url_path, secret)
    start_response = requests.post(frontend_url + url_path, data={"signature": signature})
    if start_response.status_code > 299:
        raise ValueError("Unable to start transfer:" + start_response.text)
    return start_response.json()["filepath"]
示例#2
0
def expose_path(group):
    form_keys = ["path", "size", "hash", "hash_function", "modified", "signature"]
    for key in form_keys:
        if key not in request.form:
            raise ValueError("Missing form value %s" % key)
    path = request.form["path"]
    signature = request.form["signature"]

    # Don't include signature
    d = {k: request.form[k] for k in form_keys[:-1]}

    if not security.check_json_sig(d, app.config["BASEJUMP_KEY"], signature):
        raise ValueError("Invalid signature provided.")

    key = security.sign_path(path, app.config["SECRET_KEY"])

    meta = request.form
    with db_session() as s:
        f = s.query(File).filter(File.key == key).all()
        if f:
            raise ValueError("This path is already exposed.")

        last_modified = datetime.fromtimestamp(int(meta["modified"]))
        f = File(path=path, group=group, key=key, size=meta["size"], checksum=meta["hash"], checksumType=meta["hash_function"], modified=last_modified)
        s.add(f)
        s.commit()
        url_path = f.queue_url()
    url = request.url_root + url_path
    return jsonify({"queue_url": url})
示例#3
0
def complete_transfer(tid):
    url_path = "/transfers/{tid}/complete".format(tid=tid)
    signature = security.sign_path(tid, secret)
    complete_response = requests.post(frontend_url + url_path, data={"signature": signature})
    if complete_response.status_code > 299:
        raise ValueError("Unable to complete transfer:" + complete_response.text)
示例#4
0
def update_progress(tid, progress):
    url_path = "/transfers/{tid}/progress".format(tid=tid)
    signature = security.sign_path(str(progress), secret)
    prog_response = requests.post(frontend_url + url_path, data={"progress": progress, "signature": signature})
    if prog_response.status_code > 299:
        raise ValueError("Unable to update transfer progress:" + prog_response.text)
示例#5
0
def get_transfers():
    stamp = str((datetime.datetime.now() - datetime.datetime(1970, 1, 1)).total_seconds())
    transfer_response = requests.get(frontend_url + "/queue?timestamp={}&signature={}".format(stamp, security.sign_path(stamp, secret)))
    if transfer_response.status_code > 299:
        raise ValueError("Unable to retrieve transfers:" + transfer_response.text)
    return transfer_response.json()