use serde::{Deserialize, Serialize};
use super::StorageError;
use crate::config::{merge_option_if_set, prefixed_env_var};
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct LocalStoreConfig {
pub base_path: Option<String>,
}
impl LocalStoreConfig {
pub fn new(base_path: Option<String>) -> Self {
Self { base_path }
}
pub fn from_env(prefix: &str) -> Result<Self, StorageError> {
Ok(Self {
base_path: prefixed_env_var(prefix, "LOCAL_BASE_PATH").ok(),
})
}
pub fn merge_env(&mut self, prefix: &str) -> Result<(), StorageError> {
let from_env = Self::from_env(prefix)?;
merge_option_if_set(&mut self.base_path, from_env.base_path);
Ok(())
}
#[cfg(feature = "filigree-cli")]
pub fn template_text(&self) -> String {
use crate::templates::OptionAsString;
format!(
"StorageConfig::Local(filigree::storage::local::LocalStoreConfig {{ base_path: {} }})",
OptionAsString(&self.base_path)
)
}
}