supercode-interchange 0.4.20

Canonical, provider-neutral session interchange primitives for Supercode
Documentation
//! Secret references. A credential is named, never held: the model carries
//! WHERE a value lives (`docs/ORCHESTRATOR-IR.md` ยง1 rule 3), and a vault
//! resolves it at the moment of use.

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

/// Where a secret value lives. Wire form: `{"env": NAME}` or `{"dotenv": KEY}`.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum SecretRef {
    /// An environment variable of the process that resolves it.
    Env(String),
    /// A key in the home's own `.env` file.
    Dotenv(String),
}

impl SecretRef {
    /// The name the reference points at, whichever store holds it.
    pub fn name(&self) -> &str {
        match self {
            Self::Env(n) | Self::Dotenv(n) => n,
        }
    }
}

/// Resolves references at use; never part of a serialized model.
pub trait Vault {
    /// The value behind `reference`, or `None` when the store has no such name.
    fn resolve(&self, reference: &SecretRef) -> Option<String>;
}