pub struct AuthStorage { /* private fields */ }Expand description
Main auth storage struct.
Provides multi-layered credential lookup with the following priority:
- Runtime override (CLI –api-key)
- Stored API key from auth.json
- OAuth token from auth.json (with auto-refresh awareness)
- Session token from auth.json
- Environment variable
- Fallback resolver (e.g., custom provider config from models.json)
Implementations§
Source§impl AuthStorage
impl AuthStorage
Sourcepub fn new() -> AuthStorage
pub fn new() -> AuthStorage
Create a new auth storage with default file backend
Sourcepub fn with_backend(backend: impl AuthStorageBackend + 'static) -> AuthStorage
pub fn with_backend(backend: impl AuthStorageBackend + 'static) -> AuthStorage
Create with explicit storage backend
Sourcepub fn in_memory() -> AuthStorage
pub fn in_memory() -> AuthStorage
Create a memory-only storage (for testing)
Sourcepub fn default_path() -> Option<PathBuf>
pub fn default_path() -> Option<PathBuf>
Get the default auth file path
Sourcepub fn set_runtime_key(&self, provider: &str, api_key: String)
pub fn set_runtime_key(&self, provider: &str, api_key: String)
Set a runtime API key override (from CLI –api-key)
Sourcepub fn remove_runtime_key(&self, provider: &str)
pub fn remove_runtime_key(&self, provider: &str)
Remove a runtime override
Sourcepub fn set_fallback_resolver(&self, resolver: Arc<dyn FallbackResolver>)
pub fn set_fallback_resolver(&self, resolver: Arc<dyn FallbackResolver>)
Set a fallback resolver for API keys not found in auth.json or env vars. Used for custom provider keys from models.json.
Sourcepub fn clear_fallback_resolver(&self)
pub fn clear_fallback_resolver(&self)
Clear the fallback resolver
Sourcepub fn get_status(&self, provider: &str) -> AuthStatus
pub fn get_status(&self, provider: &str) -> AuthStatus
Get auth status for a provider (without exposing credentials)
Sourcepub fn get_api_key(&self, provider: &str) -> Option<String>
pub fn get_api_key(&self, provider: &str) -> Option<String>
Get API key for a provider.
Priority:
- Runtime override (CLI –api-key)
- Stored API key from auth.json
- OAuth token from auth.json (auto-refreshed)
- Session token from auth.json
- Fallback resolver
Sourcepub fn get_api_key_with_options(
&self,
provider: &str,
include_fallback: bool,
) -> Option<String>
pub fn get_api_key_with_options( &self, provider: &str, include_fallback: bool, ) -> Option<String>
Get API key with option to include/exclude fallback resolver
Sourcepub fn set_api_key(&self, provider: &str, key: String)
pub fn set_api_key(&self, provider: &str, key: String)
Set API key for a provider
Sourcepub fn set_oauth(
&self,
provider: &str,
access_token: String,
refresh_token: Option<String>,
expires_at: u64,
)
pub fn set_oauth( &self, provider: &str, access_token: String, refresh_token: Option<String>, expires_at: u64, )
Set OAuth credential for a provider
Sourcepub fn set_oauth_full(
&self,
provider: &str,
access_token: String,
refresh_token: Option<String>,
expires_at: u64,
scopes: Option<String>,
provider_data: Option<Value>,
)
pub fn set_oauth_full( &self, provider: &str, access_token: String, refresh_token: Option<String>, expires_at: u64, scopes: Option<String>, provider_data: Option<Value>, )
Set OAuth credential with full details
Sourcepub fn set_session(
&self,
provider: &str,
token: String,
expires_at: u64,
metadata: Option<Value>,
)
pub fn set_session( &self, provider: &str, token: String, expires_at: u64, metadata: Option<Value>, )
Set session token for a provider
Sourcepub fn update_oauth_tokens(
&self,
provider: &str,
new_access_token: String,
new_refresh_token: Option<String>,
new_expires_at: u64,
) -> Result<(), AuthError>
pub fn update_oauth_tokens( &self, provider: &str, new_access_token: String, new_refresh_token: Option<String>, new_expires_at: u64, ) -> Result<(), AuthError>
Update an existing OAuth credential (for token refresh)
Sourcepub fn get(&self, provider: &str) -> Option<AuthCredential>
pub fn get(&self, provider: &str) -> Option<AuthCredential>
Get credential for a provider
Sourcepub fn get_oauth_credential(&self, provider: &str) -> Option<AuthCredential>
pub fn get_oauth_credential(&self, provider: &str) -> Option<AuthCredential>
Get OAuth credential for a provider (for token refresh)
Sourcepub fn has_oauth_with_refresh(&self, provider: &str) -> bool
pub fn has_oauth_with_refresh(&self, provider: &str) -> bool
Check if a provider has OAuth credentials that can be refreshed
Sourcepub fn set(&self, provider: &str, credential: AuthCredential)
pub fn set(&self, provider: &str, credential: AuthCredential)
Set a credential for a provider
Sourcepub fn list_providers(&self) -> Vec<String>
pub fn list_providers(&self) -> Vec<String>
List all providers with credentials
Sourcepub fn get_all(&self) -> HashMap<String, AuthCredential>
pub fn get_all(&self) -> HashMap<String, AuthCredential>
Get all credentials
Sourcepub fn drain_errors(&self) -> Vec<AuthError>
pub fn drain_errors(&self) -> Vec<AuthError>
Drain collected errors
Sourcepub fn load_error(&self) -> Option<AuthError>
pub fn load_error(&self) -> Option<AuthError>
Get the last load error
Sourcepub fn validate_all(&self) -> Vec<(String, CredentialValidationError)>
pub fn validate_all(&self) -> Vec<(String, CredentialValidationError)>
Validate all stored credentials
Sourcepub fn validate(&self, provider: &str) -> Result<(), CredentialValidationError>
pub fn validate(&self, provider: &str) -> Result<(), CredentialValidationError>
Validate credential for a specific provider
Sourcepub fn configured_providers(&self) -> Vec<String>
pub fn configured_providers(&self) -> Vec<String>
Get all configured provider IDs (sorted)
Sourcepub fn has_multiple_providers(&self) -> bool
pub fn has_multiple_providers(&self) -> bool
Check if multiple providers are configured
Sourcepub fn primary_provider(&self) -> Option<String>
pub fn primary_provider(&self) -> Option<String>
Get the primary provider (first configured, preferring stored over env)
Trait Implementations§
Source§impl Default for AuthStorage
impl Default for AuthStorage
Source§fn default() -> AuthStorage
fn default() -> AuthStorage
Auto Trait Implementations§
impl !Freeze for AuthStorage
impl !RefUnwindSafe for AuthStorage
impl Send for AuthStorage
impl Sync for AuthStorage
impl Unpin for AuthStorage
impl UnsafeUnpin for AuthStorage
impl !UnwindSafe for AuthStorage
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
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
self file descriptor. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more