pub struct AuthStorage { /* private fields */ }Expand description
Credential storage (file-backed, read-only and in-memory backends) with a runtime-credentials overlay.
Implementations§
Source§impl AuthStorage
impl AuthStorage
Sourcepub fn open_read_only(path: impl Into<PathBuf>) -> Self
pub fn open_read_only(path: impl Into<PathBuf>) -> Self
Validates every entry and refuses mutations.
Sourcepub fn in_memory(data: IndexMap<String, AuthCredential>) -> Self
pub fn in_memory(data: IndexMap<String, AuthCredential>) -> Self
The auth storage.in memory(data) record.
Sourcepub fn with_env(self, env: Arc<dyn EnvSource>) -> Self
pub fn with_env(self, env: Arc<dyn EnvSource>) -> Self
Replaces the environment used to resolve $ENV keys (default: the process env).
Sourcepub fn is_read_only(&self) -> bool
pub fn is_read_only(&self) -> bool
Whether mutations are refused.
Sourcepub fn stored(
&self,
provider: &str,
) -> Result<Option<AuthCredential>, AuthStorageError>
pub fn stored( &self, provider: &str, ) -> Result<Option<AuthCredential>, AuthStorageError>
The stored credential exactly as written (no runtime overlay, no key resolution;
Reads a stored credential). Entries of unknown shape read as None.
§Errors
Read-only storage reports unreadable or invalid files.
Sourcepub fn get(
&self,
provider: &str,
) -> Result<Option<AuthCredential>, AuthStorageError>
pub fn get( &self, provider: &str, ) -> Result<Option<AuthCredential>, AuthStorageError>
The runtime key if set, else the stored credential with an API key’s config
value resolved (!command cached, $ENV with the credential’s env first). A key that
does not resolve becomes None.
§Errors
Read-only storage reports unreadable or invalid files.
Sourcepub fn list(&self) -> Result<Vec<CredentialInfo>, AuthStorageError>
pub fn list(&self) -> Result<Vec<CredentialInfo>, AuthStorageError>
Stored entries plus runtime keys (as api_key).
§Errors
Read-only storage reports unreadable or invalid files.
Sourcepub fn has(&self, provider: &str) -> bool
pub fn has(&self, provider: &str) -> bool
Whether a credential (stored or runtime) exists for provider.
Sourcepub fn has_stored(&self, provider: &str) -> bool
pub fn has_stored(&self, provider: &str) -> bool
Whether auth.json holds an entry for provider (runtime keys excluded).
Sourcepub fn set(
&self,
provider: &str,
credential: &AuthCredential,
) -> Result<(), AuthStorageError>
pub fn set( &self, provider: &str, credential: &AuthCredential, ) -> Result<(), AuthStorageError>
Sourcepub fn modify(
&self,
provider: &str,
f: impl FnOnce(Option<AuthCredential>) -> Option<AuthCredential>,
) -> Result<Option<AuthCredential>, AuthStorageError>
pub fn modify( &self, provider: &str, f: impl FnOnce(Option<AuthCredential>) -> Option<AuthCredential>, ) -> Result<Option<AuthCredential>, AuthStorageError>
Modify (synchronous): f receives the current credential under the lock; Some
replaces it, None leaves the file untouched. Returns the credential after the call.
§Errors
Lock, write or read-only failures.
Sourcepub async fn modify_async<F, Fut, E>(
&self,
provider: &str,
f: F,
) -> Result<Option<AuthCredential>, E>where
F: FnOnce(Option<AuthCredential>) -> Fut,
Fut: Future<Output = Result<Option<AuthCredential>, E>>,
E: From<AuthStorageError>,
pub async fn modify_async<F, Fut, E>(
&self,
provider: &str,
f: F,
) -> Result<Option<AuthCredential>, E>where
F: FnOnce(Option<AuthCredential>) -> Fut,
Fut: Future<Output = Result<Option<AuthCredential>, E>>,
E: From<AuthStorageError>,
Modify with an asynchronous callback (OAuth refresh). Concurrent calls in this
process are serialized; the file lock is held while f runs, so other processes
refresh at most once.
§Errors
Storage failures (converted into E) or the callback’s error; on error nothing is
written.
Sourcepub fn set_runtime_api_key(&self, provider: &str, key: impl Into<String>)
pub fn set_runtime_api_key(&self, provider: &str, key: impl Into<String>)
A non-persistent key that wins over auth.json.
Sourcepub fn remove_runtime_api_key(&self, provider: &str)
pub fn remove_runtime_api_key(&self, provider: &str)
R e m o v e R u n t i m e A p i K e y.
Sourcepub fn has_runtime_api_key(&self, provider: &str) -> bool
pub fn has_runtime_api_key(&self, provider: &str) -> bool
Returns whether runtime api key is present.