Skip to main content

Crate zerodds_config

Crate zerodds_config 

Source
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:

  1. the base file, if there is one,
  2. each drop-in directory in the order it was added, and inside one directory its files sorted by name — 10-net.yaml before 20-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§

CommandLine
What the configuration flags on a command line said.
Config
A merged configuration, and where each of its values came from.
Loader
Builds a Config out of a base file and drop-in directories.
SystemLayout
Where a platform keeps the system configuration of one ZeroDDS program.

Enums§

ConfigError
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 Config holding only the environment layer, ready for crate::Loader::load_onto. Empty and without a source entry when no variable of table is set.
env_layer
The environment layer: one value per variable of table that lookup finds, 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 under auth.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 PATH is a required base with its sibling <stem>.d, otherwise the system layout for stem.
origins
Every path in a tree, dotted, with the origin of its scalar.
parse_str
Reads text as the configuration subset.
path_node
A tree holding one value at a dotted path.
unknown_keys
Every scalar path in config that known does not accept, with where it came from. A sequence element is reported by its sequence’s path.