aboutsummaryrefslogtreecommitdiffstats
path: root/src/config/file.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-17 16:18:58 +0000
committertv <tv@krebsco.de>2026-11-17 17:36:10 +0100
commit7fc844ff0167fb0943e3fa85af671d8f3bbf005d (patch)
treeea7a759bfdfbd1705b64f6a1083ae42d9c84515c /src/config/file.rs
parente9b1ea18694c88abe1e31f8236f8d8beb6362be9 (diff)
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.
Diffstat (limited to 'src/config/file.rs')
-rw-r--r--src/config/file.rs23
1 files changed, 17 insertions, 6 deletions
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<Layer> {
- 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<Layer> {
+ load_inner(path, options, &mut Vec::new())
}
-fn load_inner(path: &Path, loading: &mut Vec<PathBuf>) -> Result<Layer> {
+fn load_inner(
+ path: &Path,
+ options: &'static [OptionSpec],
+ loading: &mut Vec<PathBuf>,
+) -> Result<Layer> {
let canonical = path
.canonicalize()
.with_context(|| format!("configuration file {}", path.display()))?;
@@ -58,7 +69,7 @@ fn load_inner(path: &Path, loading: &mut Vec<PathBuf>) -> Result<Layer> {
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<PathBuf>) -> Result<Layer> {
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<PathBuf>) -> Result<Layer> {
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()))?;