Skip to content

Commit 07104ee

Browse files
committed
project: get blessed helm version
Get the blessed version instead of the latest version.
1 parent 3d8bb99 commit 07104ee

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/warnet/project.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
import inquirer
1616
import requests
1717

18-
from .constants import HELM_BINARY_NAME, HELM_DOWNLOAD_URL_STUB, HELM_LATEST_URL
18+
from .constants import (
19+
HELM_BINARY_NAME,
20+
HELM_BLESSED_NAME_AND_CHECKSUMS,
21+
HELM_BLESSED_VERSION,
22+
HELM_DOWNLOAD_URL_STUB,
23+
HELM_LATEST_URL,
24+
)
1925
from .graph import inquirer_create_network
2026
from .network import copy_network_defaults, copy_scenario_defaults
2127

@@ -431,6 +437,17 @@ def get_latest_version_of_helm() -> Optional[str]:
431437
return None
432438

433439

440+
def write_blessed_checksum(helm_filename: str, dest_path: str):
441+
checksum = next(
442+
(b["checksum"] for b in HELM_BLESSED_NAME_AND_CHECKSUMS if b["name"] == helm_filename), None
443+
)
444+
if checksum:
445+
with open(dest_path, "w") as f:
446+
f.write(checksum)
447+
else:
448+
click.secho("Could not find a matching helm binary and checksum", fg="red")
449+
450+
434451
def verify_checksum(file_path, checksum_path):
435452
click.secho(" Verifying checksum...", fg="blue")
436453
sha256_hash = hashlib.sha256()
@@ -462,13 +479,7 @@ def install_helm_rootlessly_to_venv():
462479
)
463480
sys.exit(1)
464481

465-
version = get_latest_version_of_helm()
466-
if version is None:
467-
click.secho(
468-
"Error: Could not fetch the latest version of Helm. Please check your internet connection.",
469-
fg="yellow",
470-
)
471-
sys.exit(1)
482+
version = HELM_BLESSED_VERSION
472483

473484
os_name = get_os_name_for_helm()
474485
if os_name is None:
@@ -497,15 +508,14 @@ def install_helm_rootlessly_to_venv():
497508

498509
helm_filename = f"{HELM_BINARY_NAME}-{version}-{os_name}-{arch}.tar.gz"
499510
helm_url = f"{HELM_DOWNLOAD_URL_STUB}{helm_filename}"
500-
checksum_url = f"{helm_url}.sha256"
501511

502512
try:
503513
with tempfile.TemporaryDirectory() as temp_dir:
504514
helm_archive_path = os.path.join(temp_dir, helm_filename)
505515
checksum_path = os.path.join(temp_dir, f"{helm_filename}.sha256")
506516

507517
download_file(helm_url, helm_archive_path)
508-
download_file(checksum_url, checksum_path)
518+
write_blessed_checksum(helm_filename, checksum_path)
509519
verify_checksum(helm_archive_path, checksum_path)
510520

511521
# Extract Helm and install it in the virtual environment's bin folder

0 commit comments

Comments
 (0)