mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 03:38:23 +00:00
Mint the node onion during provisioning and write its address straight into applications.svc-net-tor.services.tor.node, dropping the INFINITO_TOR_NODE_ONION env indirection: ensure_node_onion (was init_env) mints/reuses the .onion-identity key files + returns the address (no env write); identity_hs_dir/IDENTITY_DIRNAME move to utils.tor_onion so cli and utils share the path SPOT; provision.apply_tor_node_onion sets services.tor.node in host_vars when svc-net-tor is deployed (run by 'inventory provision' at deploy time, and the svc-net-tor role copies the same key files into the daemon); domains.py reads services.tor.node; nginx_vhosts reads the key file instead of os.environ; INFINITO_TOR_NODE_ONION removed from default.env/passthrough/compose + the inventory env-lookup. Bonus: the address now lives in the persistent key files, surviving .env regeneration by make test/autoformat. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
"""Provision the node onion address into ``services.tor.node``.
|
|
|
|
The onion identity (key files) is minted/reused by
|
|
``cli.administration.inventory.onion``; this provisioner is the single spot that
|
|
writes the resulting address into
|
|
``applications.svc-net-tor.services.tor.node`` of the host_vars — so consumers
|
|
read it via ``lookup('config', 'svc-net-tor', 'services.tor.node')`` with no env
|
|
indirection.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from cli.administration.inventory.onion import ensure_node_onion
|
|
|
|
from .yaml_io import dump_yaml, load_yaml
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
_PROVIDER = "svc-net-tor"
|
|
|
|
|
|
def apply_tor_node_onion(
|
|
*,
|
|
host_vars_file: Path,
|
|
application_ids: list[str],
|
|
base_dir: Path,
|
|
) -> None:
|
|
"""When ``svc-net-tor`` is in the deploy, mint (or reuse) the node onion and
|
|
set ``applications.svc-net-tor.services.tor.node`` in the host_vars."""
|
|
if _PROVIDER not in application_ids:
|
|
return
|
|
address = ensure_node_onion(base_dir)
|
|
data = load_yaml(host_vars_file) if host_vars_file.exists() else {}
|
|
if not isinstance(data, dict):
|
|
data = {}
|
|
apps = data.setdefault("applications", {})
|
|
svc = apps.setdefault(_PROVIDER, {})
|
|
services = svc.setdefault("services", {})
|
|
tor = services.setdefault("tor", {})
|
|
tor["node"] = address
|
|
dump_yaml(host_vars_file, data)
|