Added helper function to load file content as base64

This commit is contained in:
2025-12-01 01:59:08 +01:00
parent b0a1d04d7d
commit 1da24905ef

View File

@@ -3,6 +3,7 @@
# Adapted from: https://enix.io/en/blog/pxe-talos/ # Adapted from: https://enix.io/en/blog/pxe-talos/
import base64
import functools import functools
import json import json
import pathlib import pathlib
@@ -71,6 +72,9 @@ def tailscale_subnet(gateway: str, netmask: str):
netmask_bits = IPAddress(netmask).netmask_bits() netmask_bits = IPAddress(netmask).netmask_bits()
return f"{IPAddress(gateway) & IPAddress(netmask)}/{netmask_bits}" return f"{IPAddress(gateway) & IPAddress(netmask)}/{netmask_bits}"
def load_secret(path: str):
with open(path) as f:
return base64.b64encode(f.read().encode()).decode()
@functools.cache @functools.cache
def get_schematic_id(schematic: str): def get_schematic_id(schematic: str):
@@ -165,7 +169,7 @@ def main():
template_args = { template_args = {
"config": config, "config": config,
"root": ROOT, "root": ROOT,
"helper": {"tailscale_subnet": tailscale_subnet}, "helper": {"tailscale_subnet": tailscale_subnet, "load_secret": load_secret},
} }
nodes = [] nodes = []