Skip to content

Commit

Permalink
download_hash.py: support for 'multi-hash' file + runc
Browse files Browse the repository at this point in the history
runc upstream does not provide one hash file per assets in their
releases, but one file with all the hashes.
To handle this (and/or any arbitrary format from upstreams), add a
dictionary mapping the name of the download to a lambda function which
transform the file provided by upstream into a dictionary of hashes,
keyed by architecture.
  • Loading branch information
VannTen committed Sep 8, 2024
1 parent a761623 commit da0e445
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions scripts/download_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ def download_hash(minors):
"kubeadm": "https://dl.k8s.io/release/{version}/bin/linux/{arch}/kubeadm.sha256",
"kubectl": "https://dl.k8s.io/release/{version}/bin/linux/{arch}/kubectl.sha256",
"kubelet": "https://dl.k8s.io/release/{version}/bin/linux/{arch}/kubelet.sha256",
"runc": "https://github.com/opencontainers/runc/releases/download/{version}/runc.{arch}.sha256sum",
"runc": "https://github.com/opencontainers/runc/releases/download/{version}/runc.sha256sum",
}
# Handle hashes not directly in one url per hash. Return dict of hashs indexed by arch
download_hash_extract = {
"runc": lambda hashes : {
parts[1].split('.')[1] : parts[0]
for parts in (line.split()
for line in hashes.split('\n')[3:9])
},
}

data, yaml = open_checksums_yaml()

Expand All @@ -61,7 +69,13 @@ def download_hash(minors):
print(f"Unable to find {download} hash file for version {version} (arch: {arch}) at {hash_file.url}")
break
hash_file.raise_for_status()
sha256sum = hash_file.content.decode().split(' ')[0]
sha256sum = hash_file.content.decode()
if download in download_hash_extract:
sha256sum = download_hash_extract[download](sha256sum).get(arch)
if sha256sum == None:
break
sha256sum = sha256sum.split()[0]

if len(sha256sum) != 64:
raise Exception(f"Checksum has an unexpected length: {len(sha256sum)} (binary: {download}, arch: {arch}, release: {version}, checksum: '{sha256sum}')")
data[checksum_name][arch][version] = sha256sum
Expand Down

0 comments on commit da0e445

Please sign in to comment.