From 7fc844ff0167fb0943e3fa85af671d8f3bbf005d Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 17 Nov 2026 16:18:58 +0000 Subject: continuum-party: options from configuration files, as the node's `continuum-party` takes its options (`node`, `token`, `key`, `record`: `config::PARTY_OPTIONS`) on the command line and in configuration files of the node's format: `--config`, repeatable, arguments winning, `--unset`, includes and imports. The configuration's loader takes the options it reads as a table (`config::with_options`, `config::merged`, `file::load_with`), the node's or the client's, and a key naming none of them is an error in either; `node` and `token` are secrets, never logged. --- src/config/file.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/config/file.rs') diff --git a/src/config/file.rs b/src/config/file.rs index bd6a3d5..ee71133 100644 --- a/src/config/file.rs +++ b/src/config/file.rs @@ -17,18 +17,29 @@ use serde_json::{Map as JsonMap, Value as JsonValue}; use tracing::debug; use super::import; -use super::{Entry, Layer, Overlay, Provenance, UNSET, overlay, spec, unset_entry}; +use super::{Entry, Layer, OptionSpec, Overlay, Provenance, UNSET, overlay, spec_in, unset_entry}; const INCLUDE: &str = "include"; /// Gone: optional includes are entries of `include`, so the order is the list's. const INCLUDE_OPTIONAL: &str = "include-optional"; /// The settings `path` makes, its includes resolved. +#[cfg(test)] pub(super) fn load(path: &Path) -> Result { - load_inner(path, &mut Vec::new()) + load_with(path, super::OPTIONS) +} + +/// The settings `path` makes of `options`, its includes resolved: a key naming none of +/// them is an error. +pub(super) fn load_with(path: &Path, options: &'static [OptionSpec]) -> Result { + load_inner(path, options, &mut Vec::new()) } -fn load_inner(path: &Path, loading: &mut Vec) -> Result { +fn load_inner( + path: &Path, + options: &'static [OptionSpec], + loading: &mut Vec, +) -> Result { let canonical = path .canonicalize() .with_context(|| format!("configuration file {}", path.display()))?; @@ -58,7 +69,7 @@ fn load_inner(path: &Path, loading: &mut Vec) -> Result { debug!(file = %include.display(), "Optional configuration file is missing; skipped"); continue; } - let included = load_inner(&include, loading) + let included = load_inner(&include, options, loading) .with_context(|| format!("included from {}", canonical.display()))?; for (name, entry) in included { overlay(&mut layer, name, entry, Overlay::IncludeOverInclude); @@ -67,7 +78,7 @@ fn load_inner(path: &Path, loading: &mut Vec) -> Result { loading.pop(); for name in unsets { - if spec(&name).is_none() { + if spec_in(options, &name).is_none() { bail!( "unknown option {name:?} in unset, in {}", canonical.display() @@ -80,7 +91,7 @@ fn load_inner(path: &Path, loading: &mut Vec) -> Result { let mut own = Vec::new(); flatten(&root, "", &dir, &mut own).with_context(|| format!("in {}", canonical.display()))?; for (name, value) in own { - let spec = spec(&name) + let spec = spec_in(options, &name) .ok_or_else(|| anyhow!("unknown option {name:?} in {}", canonical.display()))?; let (value, sources) = super::resolve_file_value(spec, value, &dir) .with_context(|| format!("option {name} in {}", canonical.display()))?; -- cgit v1.3.1