use crate::{ProviderError, ProviderResult};
use appcore_contracts::SecretRef;
use std::fmt::{Debug, Formatter};
use zeroize::Zeroizing;
pub struct ResolvedSecret(Zeroizing<String>);
impl ResolvedSecret {
pub fn new(value: impl Into<String>) -> ProviderResult<Self> {
let value = value.into();
if value.trim().is_empty() {
return Err(ProviderError::SecretUnavailable(
"resolved value is empty".to_string(),
));
}
Ok(Self(Zeroizing::new(value)))
}
pub fn expose(&self) -> &str {
self.0.as_str()
}
pub fn into_zeroizing(self) -> Zeroizing<String> {
self.0
}
}
impl Debug for ResolvedSecret {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
formatter.write_str("ResolvedSecret(REDACTED)")
}
}
pub trait SecretProvider: Send + Sync {
fn resolve(&self, reference: &SecretRef) -> ProviderResult<ResolvedSecret>;
}