From 2b1b9628490c4a810510393f17e27589a35e0d41 Mon Sep 17 00:00:00 2001 From: anti Date: Sun, 19 Apr 2026 03:17:25 -0400 Subject: [PATCH] feat(env): run decnet.ini loader at package import; expose DECNET_MODE - decnet/__init__.py now calls load_ini_config() on first import of any decnet.* module, seeding os.environ via setdefault() so env.py's module-level reads pick up INI values before the shell had to export them. Real env vars still win. - env.py exposes DECNET_MODE (default 'master') and DECNET_DISALLOW_MASTER (default true), consumed by the upcoming master-command gating in cli.py. Back-compat: missing /etc/decnet/decnet.ini is a no-op. Existing .env.local + flag-based launches behave identically. --- decnet/__init__.py | 12 ++++++++++++ decnet/env.py | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/decnet/__init__.py b/decnet/__init__.py index e69de29..999a57b 100644 --- a/decnet/__init__.py +++ b/decnet/__init__.py @@ -0,0 +1,12 @@ +"""DECNET — honeypot deception-network framework. + +This __init__ runs once, on the first `import decnet.*`. It seeds +os.environ from /etc/decnet/decnet.ini (if present) so that later +module-level reads in decnet.env pick up the INI values as if they had +been exported by the shell. Real env vars always win via setdefault(). + +Kept minimal on purpose — any heavier work belongs in a submodule. +""" +from decnet.config_ini import load_ini_config as _load_ini_config + +_load_ini_config() diff --git a/decnet/env.py b/decnet/env.py index 08556ca..488e776 100644 --- a/decnet/env.py +++ b/decnet/env.py @@ -103,6 +103,17 @@ DECNET_ADMIN_USER: str = os.environ.get("DECNET_ADMIN_USER", "admin") DECNET_ADMIN_PASSWORD: str = os.environ.get("DECNET_ADMIN_PASSWORD", "admin") DECNET_DEVELOPER: bool = os.environ.get("DECNET_DEVELOPER", "False").lower() == "true" +# Host role — seeded by /etc/decnet/decnet.ini or exported directly. +# "master" = the central server (api, web, swarmctl, listener). +# "agent" = a worker node (agent, forwarder, updater). Workers gate their +# Typer CLI to hide master-only commands (see decnet/cli.py). +DECNET_MODE: str = os.environ.get("DECNET_MODE", "master").lower() +# When mode=agent, hide master-only Typer commands. Set to "false" for dual- +# role dev hosts where a single machine plays both sides. +DECNET_DISALLOW_MASTER: bool = ( + os.environ.get("DECNET_DISALLOW_MASTER", "true").lower() == "true" +) + # Tracing — set to "true" to enable OpenTelemetry distributed tracing. # Separate from DECNET_DEVELOPER so tracing can be toggled independently. DECNET_DEVELOPER_TRACING: bool = os.environ.get("DECNET_DEVELOPER_TRACING", "").lower() == "true"