(prefix)
Download and install the traefik binary to a location identified by a prefix path such as '/opt/tljh/hub/
Download and install the traefik binary to a location identified by a prefix path such as '/opt/tljh/hub/
Download and install the traefik binary to a location identified by a prefix path such as / opt / tljh / hub /
def ensure_traefik_binary(prefix):
    """Download and install the traefik binary to a location identified by a prefix path such as '/opt/tljh/hub/'"""
    traefik_bin = os.path.join(prefix, "bin", "traefik")
    if os.path.exists(traefik_bin):
        checksum = checksum_file(traefik_bin)
        if checksum == checksums[plat]:
            # already have the right binary
            # ensure permissions and we're done
            os.chmod(traefik_bin, 0o755)
            return
        else:
            print(f"checksum mismatch on {traefik_bin}")
            os.remove(traefik_bin)

    traefik_url = (
        "https://github.com/containous/traefik/releases"
        f"/download/v{traefik_version}/traefik_{plat}"
    )

    print(f"Downloading traefik {traefik_version}...")
    # download the file
    response = requests.get(traefik_url)
    if response.status_code == 206:
        raise Exception("ContentTooShort")
    with open(traefik_bin, "wb") as f:
        f.write(response.content)
    os.chmod(traefik_bin, 0o755)

    # verify that we got what we expected
    checksum = checksum_file(traefik_bin)
    if checksum != checksums[plat]:
        raise OSError(f"Checksum failed {traefik_bin}: {checksum} != {checksums[plat]}")
def ensure_traefik_binary ( prefix ) : traefik_bin = os . path . join ( prefix , "bin" , "traefik" ) if os . path . exists ( traefik_bin ) : checksum = checksum_file ( traefik_bin ) if checksum == checksums [ plat ] : # already have the right binary # ensure permissions and we're done os . chmod ( traefik_bin , 0o755 ) return else : print ( f"checksum mismatch on {traefik_bin}" ) os . remove ( traefik_bin ) traefik_url = ( "https://github.com/containous/traefik/releases" f"/download/v{traefik_version}/traefik_{plat}" ) print ( f"Downloading traefik {traefik_version}..." ) # download the file response = requests . get ( traefik_url ) if response . status_code == 206 : raise Exception ( "ContentTooShort" ) with open ( traefik_bin , "wb" ) as f : f . write ( response . content ) os . chmod ( traefik_bin , 0o755 ) # verify that we got what we expected checksum = checksum_file ( traefik_bin ) if checksum != checksums [ plat ] : raise OSError ( f"Checksum failed {traefik_bin}: {checksum} != {checksums[plat]}" )