Expand description
Crate zerodds-config. Safety classification: SAFE.
Layered configuration: a base file, sorted drop-in directories, nested includes, and — for every value that survives the merge — the file and line it came from.
§Why this exists
Three daemons carried the same YAML-subset parser in three copies
(coap-bridge::daemon::yaml, mqtt-bridge::daemon::yaml,
websocket-bridge::daemon::config), each saying in its own header that it
was identical to the others, and the runtime read 28 ZERODDS_*
environment variables straight out of RuntimeConfig::default(). A
deployment could not answer the one question an operator asks first: where
does this value come from. Nor could it ship a package default and let a
site override one field without copying the whole file.
§The model
A configuration is one tree of Nodes, built by merging sources in a
defined order. Later sources win. Every scalar remembers its Origin,
and Config::origin_of answers the operator’s question by path.
The order is fixed and dull on purpose:
- the base file, if there is one,
- each drop-in directory in the order it was added, and inside one
directory its files sorted by name —
10-net.yamlbefore20-net.yaml, the convention every systemd user already knows,
Each file first loads its includes depth first, in the listed order, then
merges its own keys. The textual position of include: does not change
this precedence. An include may name a file or an explicit directory.
Included directories use the same filename sort and extension filter as
top-level drop-ins. Subdirectories are read only when explicitly included.
Paths are relative to the file naming them. Explicit includes must exist,
unlike optional top-level drop-in directories. Cycles and excessive depth
are refused for both files and directories.
include:
- defaults.yaml
- project.d
transport:
mtu: 1400§Merging
Maps merge key by key, recursively. A scalar or sequence replaces what was
there. A key written +name appends to the sequence already at name
rather than replacing it, which is what a drop-in usually wants:
# 00-base.yaml
peers:
- 10.0.0.1
# 10-site.yaml
+peers:
- 10.0.0.2 # both, in this order
# 20-override.yaml
peers:
- 10.0.0.9 # only this one§What this is not
Not a YAML implementation. It reads the subset the daemons already used —
two-space indentation, key: value, - item (a - key: value item is a
map block that nests as written), flat flow lists of scalars
([a, "b"]), # comments, ${VAR} and ${VAR:-default} — and says so
when it meets anything else, rather than guessing. Anchors, flow
mappings, nested flow lists, multi-document streams and block scalars are
refused by name.
Modules§
- cli
- The command line of a ZeroDDS daemon, read one flag at a time.
- read
- Typed reads out of a merged tree, for a program’s own schema.
Structs§
- Command
Line - What the configuration flags on a command line said.
- Config
- A merged configuration, and where each of its values came from.
- Loader
- Builds a
Configout of a base file and drop-in directories. - System
Layout - Where a platform keeps the system configuration of one ZeroDDS program.
Enums§
- Config
Error - What can go wrong while reading a configuration.
- Node
- One node of a configuration tree.
- Origin
- Where a value came from.
Constants§
- CLI_
SOURCE - The source name the command-line layer carries in
Config::sources. - ENV_
SOURCE - The source name the environment layer carries in
Config::sources. - MAX_
INCLUDE_ DEPTH - How deep
include:may nest before the loader stops. - MAX_
NESTING_ DEPTH - How deep a configuration tree may nest.
Functions§
- env_
config - A
Configholding only the environment layer, ready forcrate::Loader::load_onto. Empty and without a source entry when no variable oftableis set. - env_
layer - The environment layer: one value per variable of
tablethatlookupfinds, at the path the table gives it. - is_
secret_ path - Whether a setting holds a secret, judged by its path segments:
auth.bearer_token,mqtt.password,oscore.master_secret, and every entry underauth.sasl_users(user name to password). A report or an origin shows***in place of such a value. A path to a key file (tls.key_file) is not a secret; its contents are. - loader_
for - The loader a command line selects:
--config PATHis a required base with its sibling<stem>.d, otherwise the system layout forstem. - origins
- Every path in a tree, dotted, with the origin of its scalar.
- parse_
str - Reads
textas the configuration subset. - path_
node - A tree holding one value at a dotted path.
- unknown_
keys - Every scalar path in
configthatknowndoes not accept, with where it came from. A sequence element is reported by its sequence’s path.