51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
import requests
|
|
import hashlib
|
|
import base64
|
|
import json
|
|
import pathlib
|
|
|
|
url = "https://storage.googleapis.com/kubernetes-release/release/v{version}/bin/linux/{arch}/{pname}"
|
|
|
|
hashes = {}
|
|
|
|
f = pathlib.Path("hashes.json")
|
|
|
|
if f.exists():
|
|
hashes = json.loads(f.read_bytes())
|
|
|
|
for pname in ["kubeadm", "kubectl", "kubelet"]:
|
|
if pname not in hashes:
|
|
hashes[pname] = {}
|
|
for arch in ["amd64", "arm64"]:
|
|
if arch not in hashes[pname]:
|
|
hashes[pname][arch] = {}
|
|
for major in [1]:
|
|
for minor in [23, 24, 25, 26, 27]:
|
|
match minor:
|
|
case 23:
|
|
patch_max = 17
|
|
case 24:
|
|
patch_max = 13
|
|
case 25:
|
|
patch_max = 9
|
|
case 26:
|
|
patch_max = 4
|
|
case 27:
|
|
patch_max = 1
|
|
case _:
|
|
raise ValueError
|
|
for patch in range(0, patch_max + 1):
|
|
version = f"{major}.{minor}.{patch}"
|
|
if version in hashes[pname][arch]:
|
|
continue
|
|
url = f"https://storage.googleapis.com/kubernetes-release/release/v{version}/bin/linux/{arch}/{pname}"
|
|
r = requests.get(url)
|
|
hash = "sha256-" + base64.b64encode(
|
|
hashlib.sha256(r.content).digest()
|
|
).decode("ascii")
|
|
hashes[pname][arch][version] = hash
|
|
print(pname, arch, version, hash)
|
|
|
|
f.write_text(json.dumps(hashes, indent=2, sort_keys=True), encoding="utf-8")
|
|
|
|
# open("hashes.json", "w").write(json.dumps(hashes))
|