keyflux 0.1.14

A CLI tool and library for synchronizing environment secrets across multiple platforms including local files, GitHub Secrets, Supabase Vault, and Vercel Secrets. It facilitates secure management and automation of sensitive data.
Documentation
use std::path::PathBuf;
use async_trait::async_trait;
use crate::error::FluxError;
use crate::file::format_manager::FormatAdapter;
use serde_yaml;
use crate::file::key_collection::KeyCollection;

pub struct YamlAdapter;




#[async_trait]
impl FormatAdapter for YamlAdapter {

    fn format_tag(&self) -> &str {
        "yaml"
    }
    fn default_file_name(&self) -> &str {
        "{name}.yaml"
    }
    fn path_valid(&self, path: &PathBuf) -> bool {
        PathBuf::from(path).extension().map_or(false, |ext| ext == "yaml" || ext == "yml")
    }

    fn load_keys(&self, path: &PathBuf) -> Result<KeyCollection, FluxError> {
        let contents = std::fs::read_to_string(path)?;
        serde_yaml::from_str(&contents).map_err(FluxError::from)
    }

    fn save_keys(&self, path: &PathBuf, keys: &KeyCollection) -> Result<(), FluxError> {
        let contents = serde_yaml::to_string(keys).map_err(FluxError::from)?;
        std::fs::write(path, contents.as_bytes())?;
        Ok(())
    }
}