pub enum SecretLoader {
Env(String),
File(Utf8PathBuf),
Plain(Secret<String>),
}
Expand description
An type that can load secrets from multiple locations
This enum is the main type of this crate and represents a secret
that can be loaded from multiple locations. This type can be converted
to a SecretString
by using SecretLoader::into_secret
or one of the TryFrom<_>
/TryInto<_>
implementations.
Variants§
Env(String)
A secret that will be loaded from an environment variable
File(Utf8PathBuf)
A secret that will be loaded from a file
Plain(Secret<String>)
A plaintext secret
Implementations§
Source§impl SecretLoader
impl SecretLoader
Sourcepub fn new<S: AsRef<str>>(val: S) -> Self
pub fn new<S: AsRef<str>>(val: S) -> Self
Constructs a new SecretLoader
from a provided str.
§Examples
use secret_loader::SecretLoader;
let env_cred = SecretLoader::new("env:SECRET");
let file_cred = SecretLoader::new("file:/some/file/path");
let plain_cred = SecretLoader::new("plaintextpasswordsarebad");
Sourcepub fn into_secret(self) -> Result<Secret<String>, LoadError>
pub fn into_secret(self) -> Result<Secret<String>, LoadError>
Converts a SecretLoader
into a SecretString
Use this method to actually ‘load’ or ‘resolve’ a usable Secret
Sourcepub fn is_env(&self) -> bool
pub fn is_env(&self) -> bool
Returns true if the secret will be loaded from an environment variable.
assert!(SecretLoader::new("env:SECRET").is_env());
Trait Implementations§
Source§impl Clone for SecretLoader
impl Clone for SecretLoader
Source§fn clone(&self) -> SecretLoader
fn clone(&self) -> SecretLoader
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for SecretLoader
impl Debug for SecretLoader
Source§impl<'de> Deserialize<'de> for SecretLoader
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for SecretLoader
Available on crate feature
serde
only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<String> for SecretLoader
impl From<String> for SecretLoader
Source§impl FromStr for SecretLoader
impl FromStr for SecretLoader
Auto Trait Implementations§
impl Freeze for SecretLoader
impl RefUnwindSafe for SecretLoader
impl Send for SecretLoader
impl Sync for SecretLoader
impl Unpin for SecretLoader
impl UnwindSafe for SecretLoader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more