pub struct AuthProfileManager { /* private fields */ }Expand description
Manages multiple API keys per provider with rotation and failover.
Keys rotate automatically when the active key fails. Failed keys enter a cooldown period before being retried.
Implementations§
Source§impl AuthProfileManager
impl AuthProfileManager
Sourcepub fn new(provider: impl Into<String>, keys: Vec<String>) -> Self
pub fn new(provider: impl Into<String>, keys: Vec<String>) -> Self
Create a new manager with the given keys.
Sourcepub fn from_env(provider: &str) -> Self
pub fn from_env(provider: &str) -> Self
Create from environment variables.
Looks for {PROVIDER}_API_KEY, {PROVIDER}_API_KEY_2, etc.
Sourcepub fn from_config(provider: &str, config: &HashMap<String, Value>) -> Self
pub fn from_config(provider: &str, config: &HashMap<String, Value>) -> Self
Create from a configuration map.
Accepts {"api_keys": [...]} or {"api_key": "..."}.
Sourcepub fn get_active_key(&mut self) -> Option<&str>
pub fn get_active_key(&mut self) -> Option<&str>
Get the current active API key, rotating if needed.
Returns None if all keys are in cooldown.
Sourcepub fn mark_success(&mut self)
pub fn mark_success(&mut self)
Mark the current key as successful.
Sourcepub fn mark_failure(&mut self, status_code: u16)
pub fn mark_failure(&mut self, status_code: u16)
Mark the current key as failed with a specific HTTP status code.
Sourcepub fn profile_count(&self) -> usize
pub fn profile_count(&self) -> usize
Number of configured profiles.
Sourcepub fn available_count(&self) -> usize
pub fn available_count(&self) -> usize
Number of currently available profiles.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AuthProfileManager
impl RefUnwindSafe for AuthProfileManager
impl Send for AuthProfileManager
impl Sync for AuthProfileManager
impl Unpin for AuthProfileManager
impl UnsafeUnpin for AuthProfileManager
impl UnwindSafe for AuthProfileManager
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