Skip to main content

genja_core/
settings.rs

1//! Configuration and settings for Genja Core.
2//!
3//! This module defines the configuration structs that drive Genja behavior,
4//! plus helpers for loading from config files and environment variables.
5//!
6//! **Key points**
7//! - All configs implement `Default` and can be created with `::default()`.
8//! - Builders allow partial configuration; missing fields are filled with defaults.
9//! - `Settings::from_file` loads JSON or YAML and validates SSH config when present.
10//!
11//! # Configuration Precedence
12//!
13//! 1. Configuration files (JSON/YAML) are loaded first
14//! 2. Environment variables provide defaults for missing fields
15//! 3. Hard-coded defaults are used as final fallback
16//!
17//! # Environment Variables
18//!
19//! The following environment variables are supported:
20//!
21//! - `GENJA_CORE_RAISE_ON_ERROR` - Controls error handling behavior (default: false)
22//! - `GENJA_INVENTORY_PLUGIN` - Inventory plugin name (default: "FileInventoryPlugin")
23//! - `GENJA_RUNNER_PLUGIN` - Runner plugin name (default: "threaded")
24//! - `GENJA_LOGGING_LEVEL` - Log level (default: "info")
25//! - `GENJA_LOGGING_LOG_FILE` - Log file path (default: "genja.log")
26//! - `GENJA_LOGGING_TO_CONSOLE` - Enable console logging (default: false)
27//!
28//! # Settings Reference
29//!
30//! See `docs/settings.md` for a complete schema summary and example config files.
31//!
32//! # Examples
33//!
34//! ## Defaults
35//! ```
36//! use genja_core::Settings;
37//!
38//! let settings = Settings::default();
39//! ```
40//!
41//! ## Builders
42//! ```
43//! use genja_core::Settings;
44//! use genja_core::settings::{LoggingConfig, RunnerConfig};
45//!
46//! let settings = Settings::builder()
47//!     .logging(LoggingConfig::builder().level("debug").build())
48//!     .runner(RunnerConfig::builder().plugin("threaded").build())
49//!     .build();
50//! ```
51//!
52//! ## Load From File
53//! ```no_run
54//! use genja_core::Settings;
55//!
56//! let settings = Settings::from_file("config.yaml")?;
57//! # Ok::<(), genja_core::ConfigLoadError>(())
58//! ```
59//!
60//! ## SSH Validation
61//! SSH config is validated automatically when calling `Settings::from_file`.
62//! For manual validation, use `SSHConfig::validate`.
63
64mod core;
65mod env_defaults;
66mod inventory;
67mod inventory_loading;
68mod logging;
69mod root;
70mod runner;
71mod ssh;
72mod ssh_loading;
73
74#[cfg(test)]
75mod tests;
76
77pub use self::core::{CoreConfig, CoreConfigBuilder};
78pub use self::inventory::{
79    InventoryConfig, InventoryConfigBuilder, OptionsConfig, OptionsConfigBuilder,
80};
81pub use self::logging::{LoggingConfig, LoggingConfigBuilder};
82pub use self::root::{Settings, SettingsBuilder};
83pub use self::runner::{RunnerConfig, RunnerConfigBuilder};
84pub use self::ssh::{SSHConfig, SSHConfigBuilder};