Skip to main content

AuthStorage

Struct AuthStorage 

Source
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

Source

pub fn open(path: impl Into<PathBuf>) -> Self

File-backed, read-write.

Source

pub fn open_read_only(path: impl Into<PathBuf>) -> Self

Validates every entry and refuses mutations.

Source

pub fn in_memory(data: IndexMap<String, AuthCredential>) -> Self

The auth storage.in memory(data) record.

Source

pub fn with_env(self, env: Arc<dyn EnvSource>) -> Self

Replaces the environment used to resolve $ENV keys (default: the process env).

Source

pub fn path(&self) -> Option<&Path>

The auth.json path for file-backed storage.

Source

pub fn is_read_only(&self) -> bool

Whether mutations are refused.

Source

pub fn reload(&self)

Forces the next read to reload the file.

Source

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.

Source

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.

Source

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.

Source

pub fn has(&self, provider: &str) -> bool

Whether a credential (stored or runtime) exists for provider.

Source

pub fn has_stored(&self, provider: &str) -> bool

Whether auth.json holds an entry for provider (runtime keys excluded).

Source

pub fn set( &self, provider: &str, credential: &AuthCredential, ) -> Result<(), AuthStorageError>

Stores credential for provider.

§Errors

Lock, write or read-only failures.

Source

pub fn remove(&self, provider: &str) -> Result<(), AuthStorageError>

Removes the stored credential and any runtime key.

§Errors

Lock, write or read-only failures.

Source

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.

Source

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.

Source

pub fn set_runtime_api_key(&self, provider: &str, key: impl Into<String>)

A non-persistent key that wins over auth.json.

Source

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.

Source

pub fn has_runtime_api_key(&self, provider: &str) -> bool

Returns whether runtime api key is present.

Trait Implementations§

Source§

impl Debug for AuthStorage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more