From da0e445d69fc9147afa719a78c7210996a54a533 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Fri, 2 Feb 2024 20:48:08 +0100 Subject: [PATCH] download_hash.py: support for 'multi-hash' file + runc 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. --- scripts/download_hash.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/download_hash.py b/scripts/download_hash.py index e3eb3bf4c..ef6e159ac 100644 --- a/scripts/download_hash.py +++ b/scripts/download_hash.py @@ -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() @@ -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