Euler source The code that runs the solver shell and this site, version 4.34.2 Repository on GitHub

Minimal KEY=VALUE reader for the scoped runtime env files under /etc/euler.

35 lines of Python Raw file Open on GitHub

#!/usr/bin/env python3.14
# -*- coding: utf-8 -*-
"""Minimal `KEY=VALUE` reader for the scoped runtime env files under `/etc/euler`.

The admin CLIs run as root and read their service's scoped env file
(`auth.env`, `msg.env`) to recover the admin token and socket path. That is the
only reason this exists: the token lives **only** in a root-readable file, never in the
operator's environment, so the CLI has to read the file the unit reads.

Shared rather than duplicated per service because :mod:`euler_webshell.msg` must not import
:mod:`euler_site.auth` (web-server-guide § Messaging). Not a dotenv implementation —
no interpolation, no export, no multi-line values; the files it reads are generated by
the setup kits and contain exactly `KEY=VALUE` lines.
"""
from __future__ import annotations

__all__ = ['env_file_values']

from pathlib import Path


def env_file_values(path: Path) -> dict[str, str]:
    """The `KEY=VALUE` pairs in *path*; empty when it is absent or unreadable."""
    values: dict[str, str] = {}
    try:
        lines = path.read_text(encoding='utf-8').splitlines()
    except OSError:
        return values
    for raw in lines:
        line = raw.strip()
        if not line or line.startswith('#') or '=' not in line:
            continue
        key, _, value = line.partition('=')
        values[key.strip()] = value.strip().strip('\'"')
    return values