Trait encrypt_config::SecretSource
source · pub trait SecretSource {
type Value: Serialize + DeserializeOwned;
type Map: IntoIterator<Item = (String, Self::Value)>;
// Required methods
fn default(&self) -> Result<Self::Map, Box<dyn Error>>;
fn path(&self) -> PathBuf;
}
Available on crate feature
secret
only.Expand description
A trait for persisted and encrypted config source.
Example
use encrypt_config::{Config, SecretSource};
use serde::{Deserialize, Serialize};
let mut config = Config::new("test");
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Foo(String);
struct SecretSourceImpl;
impl SecretSource for SecretSourceImpl {
type Value = Foo;
type Map = Vec<(String, Self::Value)>;
fn path(&self) -> std::path::PathBuf {
std::path::PathBuf::from("tests").join("secret.conf")
}
fn default(&self) -> Result<Self::Map, Box<dyn std::error::Error>> {
Ok(vec![("secret".to_owned(), Foo("secret".to_owned()))])
}
}
config.add_secret_source(SecretSourceImpl).unwrap();
assert_eq!(config.get::<_, Foo>("secret").unwrap(), Foo("secret".to_owned()));
let new_value = Foo("new secret".to_owned());
config.upgrade("secret", &new_value).unwrap();
assert_eq!(config.get::<_, Foo>("secret").unwrap(), new_value);
Required Associated Types§
sourcetype Value: Serialize + DeserializeOwned
type Value: Serialize + DeserializeOwned
The type of the config value
sourcetype Map: IntoIterator<Item = (String, Self::Value)>
type Map: IntoIterator<Item = (String, Self::Value)>
The type of the config map. It must be iterable, the first item of the tuple is the key, which should be String
only.