pub enum Secret {
Empty,
Raw(String),
Command(Command),
Keyring(KeyringEntry),
}
Expand description
The secret.
A secret can be retrieved either from a raw string, from a shell command or from a keyring entry.
Variants§
Empty
The secret is empty.
Raw(String)
The secret is contained in a raw string.
This variant is not safe to use and therefore not recommended. Yet it works well for testing purpose.
Command(Command)
The secret is exposed by the given shell command.
This variant takes the secret from the first line returned by the given shell command.
See process-lib.
Keyring(KeyringEntry)
The secret is contained in the user’s global keyring at the given entry.
See keyring-lib.
Implementations§
Source§impl Secret
impl Secret
Sourcepub fn new_command(cmd: impl ToString) -> Self
pub fn new_command(cmd: impl ToString) -> Self
Creates a new secret from the given shell command.
Sourcepub fn new_keyring_entry(entry: KeyringEntry) -> Self
pub fn new_keyring_entry(entry: KeyringEntry) -> Self
Creates a new secret from the given keyring entry.
Sourcepub fn try_new_keyring_entry(
entry: impl TryInto<KeyringEntry, Error = Error>,
) -> Result<Self>
pub fn try_new_keyring_entry( entry: impl TryInto<KeyringEntry, Error = Error>, ) -> Result<Self>
Tries to create a new secret from the given entry.
Sourcepub async fn get(&self) -> Result<String>
pub async fn get(&self) -> Result<String>
Gets the secret value.
The command-based secret execute its shell command and returns the output, and the keyring-based secret retrieves the value from the global keyring using its inner key.
Sourcepub async fn find(&self) -> Result<Option<String>>
pub async fn find(&self) -> Result<Option<String>>
Finds the secret value.
Like Secret::get
, but returns None
if the secret value
is not found or empty.
Sourcepub async fn set(&mut self, secret: impl ToString) -> Result<String>
pub async fn set(&mut self, secret: impl ToString) -> Result<String>
Updates the secret value.
This is only applicable for raw secrets and keyring-based secrets. A secret value cannot be changed for command-base secrets, since the value is the output of the command.
Sourcepub async fn set_if_keyring(&self, secret: impl ToString) -> Result<String>
pub async fn set_if_keyring(&self, secret: impl ToString) -> Result<String>
Updates the secret value of the keyring-based secret only.
This function as no effect on other secret variants.
Sourcepub async fn delete(&mut self) -> Result<()>
pub async fn delete(&mut self) -> Result<()>
Deletes the secret value and make the current secret empty.
Sourcepub async fn delete_if_keyring(&self) -> Result<()>
pub async fn delete_if_keyring(&self) -> Result<()>
Deletes the secret value of keyring-based secrets only.
This function has no effect on other variants.
Sourcepub fn replace_if_empty(&mut self, new: Self)
pub fn replace_if_empty(&mut self, new: Self)
Replaces empty secret variant with the given one.
This function has no effect on other variants.
Sourcepub fn replace_with_keyring_if_empty(
&mut self,
entry: impl ToString,
) -> Result<()>
pub fn replace_with_keyring_if_empty( &mut self, entry: impl ToString, ) -> Result<()>
Replaces empty secret variant with a keyring one.
This function has no effect on other variants.