quickseal 0.1.4

Create Kubernetes SealedSecrets with a single secure command
Documentation
//! Kubernetes Secret YAML serialization

use crate::models::SecretManifest;

/// Serialize a SecretManifest to YAML string
pub fn to_yaml(manifest: &SecretManifest) -> Result<String, anyhow::Error> {
    manifest
        .to_yaml()
        .map_err(|e| anyhow::anyhow!("Failed to serialize secret to YAML: {}", e))
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::models::{SecretKeyValue, SecretRequest};
    use std::collections::HashMap;

    #[test]
    fn test_secret_to_yaml() -> anyhow::Result<()> {
        let data = vec![SecretKeyValue::new(
            "key1".to_string(),
            "value1".to_string(),
        )?];
        let request = SecretRequest::new(
            "test-secret".to_string(),
            "default".to_string(),
            HashMap::new(),
            HashMap::new(),
            data,
        )?;
        let manifest = SecretManifest::from_request(&request);
        let yaml = to_yaml(&manifest)?;

        assert!(yaml.contains("apiVersion: v1"));
        assert!(yaml.contains("kind: Secret"));
        assert!(yaml.contains("name: test-secret"));
        assert!(yaml.contains("namespace: default"));

        Ok(())
    }
}