Skip to main content

Config

Struct Config 

Source
pub struct Config {
    pub slug: String,
    pub log_level: String,
    pub log_level_stdout: String,
    pub did_resolver_positive_ttl_secs: u64,
    pub did_resolver_negative_ttl_secs: u64,
    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: String

Short printable slug identifying this daemon instance. Used in default file names: <slug>.yaml, <slug>.bin, <slug>.log.

§log_level: String

Log level written to the log file (e.g. "info", "debug").

§log_level_stdout: String

Log level written to stdout.

§did_resolver_positive_ttl_secs: u64

Cache TTL (seconds) for successful DID document resolutions. Set to 0 to disable positive cache entries.

§did_resolver_negative_ttl_secs: u64

Cache TTL (seconds) for failed DID document resolutions. Set to 0 to disable negative cache entries.

§log_file: Option<PathBuf>

Path to the log file. None → resolved to XDG_DATA_HOME/ma/<slug>.log on first use.

§kubo_rpc_url: String

Kubo JSON-RPC API URL.

§kubo_key_alias: String

IPNS key alias registered in Kubo for this daemon.

§secret_bundle: Option<PathBuf>

Path to the encrypted secret bundle. NoneXDG_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: Mapping

Extra 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

Source

pub fn init_logging(&self) -> Result<()>

Initialise the global tracing subscriber.

Sets up:

  • A file appender writing at self.log_level to self.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

Source

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.

Source

pub fn from_yaml_str(yaml_text: &str) -> Result<Self>

Deserialize a config value from YAML text without filesystem I/O.

Source

pub fn to_yaml_string(&self) -> Result<String>

Serialize config to YAML text without filesystem I/O.

Source

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.

Source

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:

  1. Explicit CLI argument
  2. MA_<MA_DEFAULT_SLUG>_FIELD environment variable
  3. MA_FIELD environment variable (static fallback)
  4. Value from the YAML config file
  5. Built-in default
Source

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.

Source

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.

Source

pub fn ipfs_gateway_resolver(&self) -> IpfsGatewayResolver

Build a gateway-backed DID resolver using config TTL settings.

Source

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.

Source

pub fn gen_headless(args: &MaArgs, default_slug: &'static str) -> Result<()>

Generate a complete headless config:

  1. Generate a fresh SecretBundle with four random 32-byte keys.
  2. Encrypt the bundle (using args.secret_bundle_passphrase or a freshly generated random passphrase).
  3. Write the encrypted bundle to XDG_CONFIG_HOME/ma/<slug>.bin (or the path from --secret-bundle) with mode 0600.
  4. Write the YAML config to XDG_CONFIG_HOME/ma/<slug>.yaml (or the path from --config) with the passphrase in cleartext and mode 0600.
  5. Print the paths of both files to stdout.

Returns an error if either file already exists.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more