pub struct Config {
pub slug: String,
pub log_level: String,
pub log_level_stdout: String,
pub log_file: Option<PathBuf>,
pub kubo_rpc_url: String,
pub kubo_key_alias: String,
pub secret_bundle: Option<PathBuf>,
pub secret_bundle_passphrase: Option<String>,
pub config_path: Option<PathBuf>,
pub extra: Mapping,
}Expand description
Runtime configuration for a ma daemon.
Build via Config::from_args on native targets or via YAML/string
serialization helpers on wasm.
Fields§
§slug: StringShort printable slug identifying this daemon instance.
Used in default file names: <slug>.yaml, <slug>.bin, <slug>.log.
log_level: StringLog level written to the log file (e.g. "info", "debug").
log_level_stdout: StringLog level written to stdout.
log_file: Option<PathBuf>Path to the log file. None → resolved to XDG_DATA_HOME/ma/<slug>.log
on first use.
kubo_rpc_url: StringKubo JSON-RPC API URL.
kubo_key_alias: StringIPNS key alias registered in Kubo for this daemon.
secret_bundle: Option<PathBuf>Path to the encrypted secret bundle. None → XDG_CONFIG_HOME/ma/<slug>.bin.
secret_bundle_passphrase: Option<String>Passphrase to unlock the secret bundle. In headless configs this is stored in cleartext in the YAML file.
config_path: Option<PathBuf>Path where this config was loaded from or will be saved to.
extra: MappingExtra user-defined YAML keys that are not part of the core schema. Preserved during load and save so callers can extend the config freely.
Implementations§
Source§impl Config
impl Config
Sourcepub fn init_logging(&self) -> Result<()>
pub fn init_logging(&self) -> Result<()>
Initialise the global tracing subscriber.
Sets up:
- A file appender writing at
self.log_leveltoself.effective_log_file(). - A stdout writer writing at
self.log_level_stdout.
Uses try_init
so that calling this more than once (e.g. in tests) does not panic.
Source§impl Config
impl Config
Sourcepub fn new_for_storage(slug: impl AsRef<str>) -> Self
pub fn new_for_storage(slug: impl AsRef<str>) -> Self
Construct a config value suitable for wasm/local storage workflows.
This constructor is storage-agnostic and does not touch the filesystem.
Sourcepub fn from_yaml_str(yaml_text: &str) -> Result<Self>
pub fn from_yaml_str(yaml_text: &str) -> Result<Self>
Deserialize a config value from YAML text without filesystem I/O.
Sourcepub fn to_yaml_string(&self) -> Result<String>
pub fn to_yaml_string(&self) -> Result<String>
Serialize config to YAML text without filesystem I/O.
Sourcepub fn to_yaml_string_without_passphrase(&self) -> Result<String>
pub fn to_yaml_string_without_passphrase(&self) -> Result<String>
Serialize config to YAML text while excluding secret passphrase fields.
Useful for browser storage where passphrases should be provided by runtime user input instead of persisted state.
Sourcepub fn from_args(args: &MaArgs, default_slug: &'static str) -> Result<Self>
pub fn from_args(args: &MaArgs, default_slug: &'static str) -> Result<Self>
Build a Config by merging CLI arguments, environment variables, a
YAML config file, and built-in defaults.
§Required compile-time constant
Callers MUST pass a compile-time constant MA_DEFAULT_SLUG: &'static str.
This determines BOTH the default slug for file naming AND the fixed
env-var prefix MA_<MA_DEFAULT_SLUG>_*. The prefix cannot be changed
at runtime; only file naming may be overridden via --slug.
use ma_core::config::{Config, MaArgs};
let args = MaArgs::default();
let config = Config::from_args(&args, "doctest")?;
assert_eq!(config.slug, "doctest");§Priority
For each field the resolution order is:
- Explicit CLI argument
MA_<MA_DEFAULT_SLUG>_FIELDenvironment variableMA_FIELDenvironment variable (static fallback)- Value from the YAML config file
- Built-in default
Sourcepub fn effective_log_file(&self) -> Result<PathBuf>
pub fn effective_log_file(&self) -> Result<PathBuf>
The effective log file path: self.log_file if set, otherwise the
XDG default XDG_DATA_HOME/ma/<slug>.log.
Sourcepub fn effective_secret_bundle(&self) -> Result<PathBuf>
pub fn effective_secret_bundle(&self) -> Result<PathBuf>
The effective secret bundle path: self.secret_bundle if set,
otherwise the XDG default XDG_CONFIG_HOME/ma/<slug>.bin.
Sourcepub fn save(&self) -> Result<()>
pub fn save(&self) -> Result<()>
Save this config to Self::config_path as YAML with 0600
permissions. Returns an error if config_path is not set.
Known fields are serialized explicitly; extra fields are merged in afterwards so user-defined keys are preserved.
Sourcepub fn gen_headless(args: &MaArgs, default_slug: &'static str) -> Result<()>
pub fn gen_headless(args: &MaArgs, default_slug: &'static str) -> Result<()>
Generate a complete headless config:
- Generate a fresh
SecretBundlewith four random 32-byte keys. - Encrypt the bundle (using
args.secret_bundle_passphraseor a freshly generated random passphrase). - Write the encrypted bundle to
XDG_CONFIG_HOME/ma/<slug>.bin(or the path from--secret-bundle) with mode 0600. - Write the YAML config to
XDG_CONFIG_HOME/ma/<slug>.yaml(or the path from--config) with the passphrase in cleartext and mode 0600. - Print the paths of both files to stdout.
Returns an error if either file already exists.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more