evault-core 0.1.0

Core types, traits, and services for evault.
Documentation
//! [`Materializer`] — write a resolved environment to a `.env` file.

use std::collections::BTreeMap;
use std::path::Path;

use crate::error::MaterializerError;

/// Produce a `.env` file from a resolved key/value environment.
///
/// "Resolved" means the caller has already fetched values from the metadata
/// store and the secret store and applied the profile's overrides. The
/// materializer's job is purely textual: emit a well-formed `.env`, attach the
/// "generated by evault" header, and update the project `.gitignore` so the
/// file is never committed.
pub trait Materializer: Send + Sync {
    /// Write `environment` to `path`, replacing any prior content.
    ///
    /// The materializer must:
    /// - prepend a header marking the file as generated;
    /// - ensure `path`'s parent directory exists;
    /// - update a sibling `.gitignore` so that the basename of `path` is
    ///   ignored;
    /// - write atomically (write-then-rename) so partial files never appear.
    ///
    /// # Errors
    /// Returns [`MaterializerError::Io`] on file-system failure or
    /// [`MaterializerError::Backend`] for higher-level problems.
    fn materialize(
        &self,
        path: &Path,
        environment: &BTreeMap<String, String>,
    ) -> Result<(), MaterializerError>;
}