pub struct ApiKeyManager { /* private fields */ }Expand description
Manages API keys for providers with support for secure storage and retrieval
Implementations§
Source§impl ApiKeyManager
impl ApiKeyManager
Sourcepub fn register_config(&mut self, provider_id: String, config: ApiKeyConfig)
pub fn register_config(&mut self, provider_id: String, config: ApiKeyConfig)
Register an API key configuration for a provider
Sourcepub fn store_key(&mut self, provider_id: String, api_key: String)
pub fn store_key(&mut self, provider_id: String, api_key: String)
Store an API key for a provider
Sourcepub fn get_key(&self, provider_id: &str) -> Result<String, ProviderError>
pub fn get_key(&self, provider_id: &str) -> Result<String, ProviderError>
Get an API key for a provider
Retrieves API key in the following order:
- From cache (if already loaded)
- From environment variable (if configured)
- From config file (if stored)
- Error if not found
Sourcepub fn has_key(&self, provider_id: &str) -> bool
pub fn has_key(&self, provider_id: &str) -> bool
Check if an API key is available for a provider
Sourcepub fn rotate_key(
&mut self,
provider_id: String,
new_key: String,
) -> Result<(), ProviderError>
pub fn rotate_key( &mut self, provider_id: String, new_key: String, ) -> Result<(), ProviderError>
Rotate an API key for a provider
This updates the cached key and can optionally persist to config
Sourcepub fn clear_cached_key(&mut self, provider_id: &str)
pub fn clear_cached_key(&mut self, provider_id: &str)
Clear a cached API key (but not the environment variable)
Sourcepub fn clear_all_cached_keys(&mut self)
pub fn clear_all_cached_keys(&mut self)
Clear all cached API keys
Sourcepub fn load_from_env(&mut self) -> Result<(), ProviderError>
pub fn load_from_env(&mut self) -> Result<(), ProviderError>
Load API keys from environment variables
Sourcepub fn cached_key_count(&self) -> usize
pub fn cached_key_count(&self) -> usize
Get the number of cached keys
Sourcepub fn configured_providers(&self) -> Vec<String>
pub fn configured_providers(&self) -> Vec<String>
Get all provider IDs with configured API key sources
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ApiKeyManager
impl RefUnwindSafe for ApiKeyManager
impl Send for ApiKeyManager
impl Sync for ApiKeyManager
impl Unpin for ApiKeyManager
impl UnwindSafe for ApiKeyManager
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
Mutably borrows from an owned value. Read more