52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
import base64
|
|
import hashlib
|
|
import json
|
|
import pathlib
|
|
import re
|
|
|
|
import requests
|
|
|
|
url = "https://storage.googleapis.com/kubernetes-release/release/v{version}/bin/linux/{arch}/{pname}" # noqa E501
|
|
|
|
hashes = {}
|
|
|
|
f = pathlib.Path("hashes.json")
|
|
|
|
if f.exists():
|
|
hashes = json.loads(f.read_bytes())
|
|
|
|
stable = {}
|
|
major = 1
|
|
minor = 22
|
|
while True:
|
|
r = requests.get(f"https://storage.googleapis.com/k8s-release/stable-1.{minor}.txt")
|
|
if r.status_code != 200:
|
|
break
|
|
if match := re.match(rb"\Av(\d+)\.(\d+)\.(\d+)\S*\Z", r.content):
|
|
patch = int(match.group(3))
|
|
stable[(major, minor)] = patch
|
|
minor += 1
|
|
|
|
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, minor in stable.keys():
|
|
patch_max = stable[(major, minor)]
|
|
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}" # noqa E501
|
|
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))
|