pub struct CredentialPool { /* private fields */ }Expand description
The compiled credential pool (DW-080). Lives inside
CompiledProvider behind an Arc so the quarantine state can be
shared across request tasks without cloning the whole provider.
Implementations§
Source§impl CredentialPool
impl CredentialPool
Sourcepub fn new(entries: Vec<PoolEntry>, cfg: &AiCredentialPool) -> Self
pub fn new(entries: Vec<PoolEntry>, cfg: &AiCredentialPool) -> Self
Build a pool from the config block + resolved credentials.
entries must be non-empty and in the same order as the config
credentials list (the index is used for quarantine tracking).
Sourcepub fn pick(&self, request_id: &str) -> Option<&PoolEntry>
pub fn pick(&self, request_id: &str) -> Option<&PoolEntry>
Pick a credential for the next request. Skips quarantined keys; if all keys are quarantined, returns None (pool exhaustion — the caller should fail with a 429 + Retry-After).
For RoundRobin: cycles through non-quarantined keys in order.
For Weighted: uses a deterministic hash of request_id to
pick a key (same hash as canary splits), skipping quarantined
keys.
Sourcepub fn quarantine(&self, index: usize, retry_after_secs: Option<u64>)
pub fn quarantine(&self, index: usize, retry_after_secs: Option<u64>)
Quarantine a credential after a 429 from the provider. The key
is skipped for quarantine_secs (or the provider’s Retry-After,
capped at 600 seconds, if the caller passes it). Idempotent —
quarantining an already-quarantined key extends the window.
Sourcepub fn record_health(&self, index: usize, health: KeyHealth)
pub fn record_health(&self, index: usize, health: KeyHealth)
AI-09 (#198): Record per-key health from provider response
headers. Called on every provider response (200 or error).
When remaining_requests is 0 (or remaining_tokens is 0),
the key is proactively quarantined until reset_at to prevent
a 429 on the next request.
Sourcepub fn is_exhausted(&self) -> bool
pub fn is_exhausted(&self) -> bool
Returns true if all keys are currently quarantined (pool exhaustion). The caller should fail with a 429 + Retry-After.
Sourcepub fn earliest_quarantine_expiry(&self) -> Option<Instant>
pub fn earliest_quarantine_expiry(&self) -> Option<Instant>
The earliest quarantine expiry among all keys (for the Retry-After header on pool-exhaustion 429s). Returns None if no keys are quarantined.
Sourcepub fn status(&self) -> Vec<CredentialStatus>
pub fn status(&self) -> Vec<CredentialStatus>
Snapshot of the pool state for the admin API (per-key usage + quarantine status + health). Never includes secret values.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for CredentialPool
impl RefUnwindSafe for CredentialPool
impl Send for CredentialPool
impl Sync for CredentialPool
impl Unpin for CredentialPool
impl UnwindSafe for CredentialPool
Blanket Implementations§
§impl<T> AnyExt for T
impl<T> AnyExt for T
§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
T behind reference§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
T behind mutable reference§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
T behind Rc pointer§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
T behind Arc pointer§fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
T behind Box pointer§fn downcast_move<T>(this: Self) -> Option<T>
fn downcast_move<T>(this: Self) -> Option<T>
Self to T,
useful only in generic context as a workaround for specializationSource§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
§impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
fn coerce_rc_to(self: Rc<X>) -> Rc<T>
fn coerce_box_to(self: Box<X>) -> Box<T>
fn coerce_ref_to(&self) -> &T
fn coerce_mut_to(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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