evault_core/traits/materializer.rs
1//! [`Materializer`] — write a resolved environment to a `.env` file.
2
3use std::collections::BTreeMap;
4use std::path::Path;
5
6use crate::error::MaterializerError;
7
8/// Produce a `.env` file from a resolved key/value environment.
9///
10/// "Resolved" means the caller has already fetched values from the metadata
11/// store and the secret store and applied the profile's overrides. The
12/// materializer's job is purely textual: emit a well-formed `.env`, attach the
13/// "generated by evault" header, and update the project `.gitignore` so the
14/// file is never committed.
15pub trait Materializer: Send + Sync {
16 /// Write `environment` to `path`, replacing any prior content.
17 ///
18 /// The materializer must:
19 /// - prepend a header marking the file as generated;
20 /// - ensure `path`'s parent directory exists;
21 /// - update a sibling `.gitignore` so that the basename of `path` is
22 /// ignored;
23 /// - write atomically (write-then-rename) so partial files never appear.
24 ///
25 /// # Errors
26 /// Returns [`MaterializerError::Io`] on file-system failure or
27 /// [`MaterializerError::Backend`] for higher-level problems.
28 fn materialize(
29 &self,
30 path: &Path,
31 environment: &BTreeMap<String, String>,
32 ) -> Result<(), MaterializerError>;
33}