pub struct Secret { /* private fields */ }Expand description
Credential manager backed by the OS keyring.
Each instance addresses one credential, identified by the account name
derived from the legacy file name (.jira_secret becomes jira), and knows
how to ask the user for it when the store has nothing.
Implementations§
Source§impl Secret
impl Secret
Sourcepub fn new(secret_name: &str, prompt: &str) -> Self
pub fn new(secret_name: &str, prompt: &str) -> Self
Creates a credential handle for the given secret.
§Arguments
secret_name- Legacy file name for the credential (e.g..jira_secret), which also determines the keyring account nameprompt- User-facing text shown when asking for the password
§Examples
use kasl::libs::secret::Secret;
let jira_secret = Secret::new(".jira_secret", "Enter your Jira password");Sourcepub fn get_or_prompt(&self) -> Result<String>
pub fn get_or_prompt(&self) -> Result<String>
Retrieves the password from the keyring, prompting when absent.
Order of resolution: keyring, then a legacy AES file (migrated on the spot), then the user. A value obtained from either of the last two is written to the keyring, so this is the only time it is asked for.
§Returns
The stored or freshly entered password.
§Errors
Returns an error when the keyring is unavailable, or when there is no terminal to prompt at and nothing stored to fall back on.
Sourcepub fn try_get_cached(&self) -> Option<String>
pub fn try_get_cached(&self) -> Option<String>
Returns a stored password without prompting the user.
Used by the background daemon, which has no terminal and must never block. Migrates a legacy file if one is found, so an unattended run benefits from the migration too.
§Returns
Some(password) when the credential is known, None otherwise.