use serde::Deserialize;
use dotenv::dotenv;
#[derive(Debug, Deserialize, Default)]
pub struct EncryptionConfig {
pub key: String,
pub iv: String,
}
#[derive(Debug, Deserialize, Default)]
pub struct DeadpoolRedisConfig {
#[serde(default)]
pub redis: deadpool_redis::Config,
}
#[derive(Debug, Deserialize, Default)]
pub struct DeadpoolPostgresConfig {
#[serde(default)]
pub postgres: deadpool_postgres::Config,
}
impl EncryptionConfig {
pub fn from_env() -> Result<Self, ::config::ConfigError> {
dotenv().ok();
let mut cfg = ::config::Config::new();
let environment = ::config::Environment::new().separator("_").prefix("ENCRYPTED_DATA_VAULT");
cfg.merge(environment).unwrap();
cfg.try_into()
}
}
impl DeadpoolRedisConfig {
pub fn from_env() -> Result<Self, ::config::ConfigError> {
dotenv().ok();
let mut cfg = ::config::Config::new();
let environment = ::config::Environment::new().separator("_");
cfg.merge(environment)?;
cfg.try_into()
}
}
impl DeadpoolPostgresConfig {
pub fn from_env() -> Result<Self, ::config::ConfigError> {
dotenv().ok();
let mut cfg = ::config::Config::new();
let environment = ::config::Environment::new().separator(".");
cfg.merge(environment)?;
cfg.try_into()
}
}