Skip to main content

CredentialStore

Struct CredentialStore 

Source
pub struct CredentialStore { /* private fields */ }

Implementations§

Source§

impl CredentialStore

Source

pub fn new(credentials: Vec<Credential>) -> Arc<Self> ⓘ

Source

pub fn end_bootstrap(&self)

Ends the startup window in which the credentials loaded before plugins parse auth files are provisional ([crate::plugins::refresh::end_bootstrap]).

Source

pub fn configure_cooldown_store(&self, dir: Option<PathBuf>)

Go ApplyConfigWithCooldownStateStore plus the restore that follows a config update: the current state goes to the old store before the swap, and a newly enabled store is restored from. None disables persistence.

Source

pub fn set_cooldown_backend(&self, backend: Arc<dyn Backend>)

Go’s builder taking the token store’s CooldownStateStore: cooldowns go to backend instead of .cds files, restored from it now when persistence is on.

Source

pub fn persist_cooldowns(&self)

Go persistCooldownStates: rewrites the .cds files from the live cooldowns.

Source

pub fn snapshot(&self) -> Vec<Arc<Credential>>

Source

pub fn get(&self, id: &str) -> Option<Arc<Credential>>

Source

pub fn select(self: &Arc<Self>, selection: Selection) -> Option<Lease>

Selects among the selection’s providers without registry admission (tests and callers that already filtered credentials).

Source

pub fn select_with( self: &Arc<Self>, selection: Selection, policy: Arc<Policy>, admit: &Admit<'_>, ) -> Result<Lease, AcquireError>

Source

pub fn select_ranked( self: &Arc<Self>, selection: Selection, policy: Arc<Policy>, admit: &Admit<'_>, ranks: &Ranks<'_>, ) -> Result<Lease, AcquireError>

Self::select_with with each credential’s usage windows (soonest-reset).

Source

pub fn suspension(&self, credential: &Credential, model: &str) -> Suspension

The registry projection of this credential’s cooldown state for model.

Source

pub fn blocked(&self, credential: &Credential, model: &str) -> bool

Whether model is cooling for this credential right now, or its tokens were refused for good. A probe reservation does not count: the lease that holds it is the one asking.

Source

pub fn tokens_rejected(&self, c: &Credential) -> bool

Whether c’s tokens were refused for good ([crate::scheduler::Scheduler::tokens_rejected]).

Source

pub fn reset_cooldown(&self, id: &str) -> Vec<String>

Clears every cooldown and affinity binding of one credential (Go ResetQuota). Returns the model keys that were cooling.

Source

pub fn retry_wait( &self, selection: &Selection, policy: &Policy, status: u16, attempted: &[String], admit: &Admit<'_>, ) -> Option<Duration>

Returns the next round’s wait, if any credential still permits that round (Go closestCooldownWaitWithAttempted). A wait exceeding the cap is rejected, not shortened. status is the round error’s status; attempted the credentials that executed this round (they get the 10s quota floor after a 429).

Source

pub fn subscribe(&self) -> Receiver<()>

Resolves after the next change to the credential set or any credential.

Source

pub fn epoch(&self) -> u64

Changes whenever the credential set or any credential changes.

Source

pub fn stats(&self) -> AttemptStats

Attempts finished so far, by outcome.

Source

pub fn prepare_lock(&self, id: &str) -> Arc<Mutex<()>> ⓘ

Serializes preparation of one credential across concurrent requests.

Source

pub fn apply_patch( &self, id: &str, expected_revision: u64, patch: &MetadataPatch, ) -> Result<Arc<Credential>, PatchError>

Applies a metadata change if the credential is still at expected_revision. File-backed credentials are written atomically (0600) before memory changes. Blocking: call from spawn_blocking in async code.

Source

pub fn replace_config_backed( &self, next: Credential, expected_revision: u64, ) -> Result<Arc<Credential>, PatchError>

Replaces a config-backed or runtime-only credential in memory if it is still at expected_revision: Go’s Manager.Update never persists config API keys (the next config publish re-synthesizes them) or runtime_only auths. NotFound unless next.id names such a credential.

Source

pub fn replace_file_backed( &self, id: &str, expected_revision: u64, bytes: &[u8], next: Option<Credential>, ) -> Result<(), PatchError>

Go Manager.Modify for an auth file: while id is still at expected_revision, writes bytes to its file and puts next (the credential re-synthesized from those bytes, possibly under a new provider or ID; None drops it) in its place. One write lock covers the check, the file and the swap, so a concurrent token refresh (Self::apply_patch) lands either before (Stale) or after, never under it, and nothing else in the set is re-read or replaced.

Source

pub fn commit_file_backed( &self, id: &str, expected_revision: u64, commit: Commit, next: Option<Credential>, ) -> Result<(), PatchError>

Self::replace_file_backed for a management save (Commit): the file check and the optional write run under the same lock and revision check, and the new revision records the save’s Provenance.

Source

pub fn provenance(&self, id: &str) -> Option<Provenance>

The Provenance of credential id, if one is known.

Source

pub fn note_loaded(&self, read: &BTreeMap<PathBuf, [u8; 32]>)

Records that the current file credentials were loaded from the bytes read hashed (an auth-folder scan’s AuthScan::read). A credential whose recorded save already holds those bytes at its revision keeps that save’s document.

Source

pub fn reconcile(&self, credentials: Vec<Credential>)

Replaces the credential set (watcher reload, management import/delete). Unchanged credentials keep their revision; new and changed ones get fresh revisions.

Source

pub fn reconcile_scanned( &self, credentials: Vec<Credential>, read: &BTreeMap<PathBuf, [u8; 32]>, ) -> Vec<PathBuf>

Self::reconcile for an auth-folder scan; read has the SHA-256 of the bytes each file credential was built from. Go c4c1d43e: a scanned credential that would replace the current one is applied only while its file still holds those bytes. Otherwise a write committed after the scan read the file (a token refresh, an edit) has changed it, and the current credential is kept: the stale snapshot would undo that write, and the watcher reloads the file it sees changed. A file that is gone or unreadable keeps the current credential too. The check runs under the exclusive reload gate, so no write lands between it and the swap, but before inner is taken, so its file reads never stall readers. Returns the files whose scanned credential was rejected.

Source

pub fn reconcile_scanned_with( &self, credentials: Vec<Credential>, read: &BTreeMap<PathBuf, [u8; 32]>, keep: impl FnOnce(&[Arc<Credential>], &mut Vec<Credential>), ) -> Vec<PathBuf>

Self::reconcile_scanned; keep first adds to the set from the current credentials, under the gate, so no write lands between what it reads and the swap.

Source

pub fn replace_config(&self, keys: Vec<Credential>)

Replaces the config-sourced credentials (Home config API keys, Go registerConfigAPIKeyAuths) under a single write lock and keeps every other current entry, so a concurrent Self::upsert or relay session change is never undone the way a snapshot followed by Self::reconcile could undo it. An unchanged key keeps its revision, as in reconcile.

Source

pub fn upsert(&self, credential: Credential)

Inserts or replaces one credential (a plugin’s host.auth.save) under a single write lock, so a concurrent apply_patch on another credential is never undone the way a snapshot followed by Self::reconcile could undo it. An unchanged credential keeps its revision, as in reconcile.

Source

pub fn upsert_file( &self, path: Option<&Path>, credentials: Vec<Credential>, saved: &[SavedRefresh], )

Self::upsert for every credential an auth file saved at path holds (Go upsertAuthRecordsForPath): the file’s other credentials, parsed from it earlier, go, runtime-only ones excepted. saved has the refresh schedules a plugin’s save registers its credentials with.

Source

pub fn add_runtime(&self, credential: Credential) -> bool

Adds a runtime-only credential (Go’s auth add for a /v1/ws relay session) unless one with its ID is already active. Additive API for the relay route.

Source

pub fn remove_runtime(&self, id: &str)

Removes a credential when its relay session ends (Go’s auth delete). Additive API for the relay route.

Source§

impl CredentialStore

Source

pub fn activity(&self, id: &str) -> CredentialActivity

Counters for one credential; zero when it has served nothing yet.

Source

pub fn cooldowns(&self, id: &str) -> Vec<CooldownState>

Active cooldowns of one credential.

Source

pub fn reset_cooldowns(&self, id: &str) -> Vec<String>

Clears the cooldowns of one credential (Go Manager.ResetQuota); returns the model keys that were cooling.

Source

pub fn recover_unauthorized(&self, id: &str)

The recovery Go runs after a token refresh and after BindCodexSIWC saves a binding: an enabled credential’s unauthorized cooldowns are cleared and persisted, live quota blocks stay. Go also forgets the rejected access token; here a pending unauthorized refresh keys on the revision, which the new tokens replaced.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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