use std::{fmt, sync::Arc};
use chrono::{DateTime, Utc};
pub mod backends;
pub mod types;
pub use backends::{EnvBackend, FileBackend, VaultBackend};
pub use types::{Secret, SecretsBackend};
pub struct SecretsManager {
backend: Arc<dyn SecretsBackend>,
}
impl SecretsManager {
pub fn new(backend: Arc<dyn SecretsBackend>) -> Self {
SecretsManager { backend }
}
pub async fn get_secret(&self, name: &str) -> Result<String, SecretsError> {
self.backend.get_secret(name).await
}
pub async fn get_secret_with_expiry(
&self,
name: &str,
) -> Result<(String, DateTime<Utc>), SecretsError> {
self.backend.get_secret_with_expiry(name).await
}
pub async fn rotate_secret(&self, name: &str) -> Result<String, SecretsError> {
self.backend.rotate_secret(name).await
}
}
#[derive(Debug, Clone)]
pub enum SecretsError {
NotFound(String),
BackendError(String),
ValidationError(String),
EncryptionError(String),
RotationError(String),
ExpiredCredential,
}
impl fmt::Display for SecretsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
SecretsError::NotFound(msg) => write!(f, "Secret not found: {}", msg),
SecretsError::BackendError(msg) => write!(f, "Backend error: {}", msg),
SecretsError::ValidationError(msg) => write!(f, "Validation error: {}", msg),
SecretsError::EncryptionError(msg) => write!(f, "Encryption error: {}", msg),
SecretsError::RotationError(msg) => write!(f, "Rotation error: {}", msg),
SecretsError::ExpiredCredential => write!(f, "Credential expired"),
}
}
}
impl std::error::Error for SecretsError {}
#[cfg(test)]
mod tests {
#[test]
fn test_secrets_manager_creation() {
assert!(true);
}
#[tokio::test]
async fn test_get_secret_from_backend() {
assert!(true);
}
#[tokio::test]
async fn test_get_secret_with_expiry() {
assert!(true);
}
#[tokio::test]
async fn test_rotate_secret() {
assert!(true);
}
#[test]
fn test_secret_redaction_in_debug() {
assert!(true);
}
#[test]
fn test_secret_expose_method() {
assert!(true);
}
#[test]
fn test_secrets_error_variants() {
assert!(true);
}
#[test]
fn test_secrets_backend_trait() {
assert!(true);
}
#[test]
fn test_backend_implementations_available() {
assert!(true);
}
#[test]
fn test_manager_with_env_backend() {
assert!(true);
}
#[test]
fn test_multiple_secret_types() {
assert!(true);
}
}