pub struct CredentialStore { /* private fields */ }Implementations§
Source§impl CredentialStore
impl CredentialStore
pub fn new(credentials: Vec<Credential>) -> Arc<Self> ⓘ
Sourcepub fn end_bootstrap(&self)
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]).
Sourcepub fn configure_cooldown_store(&self, dir: Option<PathBuf>)
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.
Sourcepub fn set_cooldown_backend(&self, backend: Arc<dyn Backend>)
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.
Sourcepub fn persist_cooldowns(&self)
pub fn persist_cooldowns(&self)
Go persistCooldownStates: rewrites the .cds files from the live cooldowns.
pub fn snapshot(&self) -> Vec<Arc<Credential>>
pub fn get(&self, id: &str) -> Option<Arc<Credential>>
Sourcepub fn select(self: &Arc<Self>, selection: Selection) -> Option<Lease>
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).
pub fn select_with( self: &Arc<Self>, selection: Selection, policy: Arc<Policy>, admit: &Admit<'_>, ) -> Result<Lease, AcquireError>
Sourcepub fn select_ranked(
self: &Arc<Self>,
selection: Selection,
policy: Arc<Policy>,
admit: &Admit<'_>,
ranks: &Ranks<'_>,
) -> Result<Lease, AcquireError>
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).
Sourcepub fn suspension(&self, credential: &Credential, model: &str) -> Suspension
pub fn suspension(&self, credential: &Credential, model: &str) -> Suspension
The registry projection of this credential’s cooldown state for model.
Sourcepub fn blocked(&self, credential: &Credential, model: &str) -> bool
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.
Sourcepub fn tokens_rejected(&self, c: &Credential) -> bool
pub fn tokens_rejected(&self, c: &Credential) -> bool
Whether c’s tokens were refused for good ([crate::scheduler::Scheduler::tokens_rejected]).
Sourcepub fn reset_cooldown(&self, id: &str) -> Vec<String>
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.
Sourcepub fn retry_wait(
&self,
selection: &Selection,
policy: &Policy,
status: u16,
attempted: &[String],
admit: &Admit<'_>,
) -> Option<Duration>
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).
Sourcepub fn subscribe(&self) -> Receiver<()>
pub fn subscribe(&self) -> Receiver<()>
Resolves after the next change to the credential set or any credential.
Sourcepub fn stats(&self) -> AttemptStats
pub fn stats(&self) -> AttemptStats
Attempts finished so far, by outcome.
Sourcepub fn prepare_lock(&self, id: &str) -> Arc<Mutex<()>> ⓘ
pub fn prepare_lock(&self, id: &str) -> Arc<Mutex<()>> ⓘ
Serializes preparation of one credential across concurrent requests.
Sourcepub fn apply_patch(
&self,
id: &str,
expected_revision: u64,
patch: &MetadataPatch,
) -> Result<Arc<Credential>, PatchError>
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.
Sourcepub fn replace_config_backed(
&self,
next: Credential,
expected_revision: u64,
) -> Result<Arc<Credential>, PatchError>
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.
Sourcepub fn replace_file_backed(
&self,
id: &str,
expected_revision: u64,
bytes: &[u8],
next: Option<Credential>,
) -> Result<(), PatchError>
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.
Sourcepub fn commit_file_backed(
&self,
id: &str,
expected_revision: u64,
commit: Commit,
next: Option<Credential>,
) -> Result<(), PatchError>
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.
Sourcepub fn provenance(&self, id: &str) -> Option<Provenance>
pub fn provenance(&self, id: &str) -> Option<Provenance>
The Provenance of credential id, if one is known.
Sourcepub fn note_loaded(&self, read: &BTreeMap<PathBuf, [u8; 32]>)
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.
Sourcepub fn reconcile(&self, credentials: Vec<Credential>)
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.
Sourcepub fn reconcile_scanned(
&self,
credentials: Vec<Credential>,
read: &BTreeMap<PathBuf, [u8; 32]>,
) -> Vec<PathBuf>
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.
Sourcepub fn reconcile_scanned_with(
&self,
credentials: Vec<Credential>,
read: &BTreeMap<PathBuf, [u8; 32]>,
keep: impl FnOnce(&[Arc<Credential>], &mut Vec<Credential>),
) -> Vec<PathBuf>
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.
Sourcepub fn replace_config(&self, keys: Vec<Credential>)
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.
Sourcepub fn upsert(&self, credential: Credential)
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.
Sourcepub fn upsert_file(
&self,
path: Option<&Path>,
credentials: Vec<Credential>,
saved: &[SavedRefresh],
)
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.
Sourcepub fn add_runtime(&self, credential: Credential) -> bool
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.
Sourcepub fn remove_runtime(&self, id: &str)
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
impl CredentialStore
Sourcepub fn activity(&self, id: &str) -> CredentialActivity
pub fn activity(&self, id: &str) -> CredentialActivity
Counters for one credential; zero when it has served nothing yet.
Sourcepub fn cooldowns(&self, id: &str) -> Vec<CooldownState>
pub fn cooldowns(&self, id: &str) -> Vec<CooldownState>
Active cooldowns of one credential.
Sourcepub fn reset_cooldowns(&self, id: &str) -> Vec<String>
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.
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§
impl !Freeze for CredentialStore
impl !RefUnwindSafe for CredentialStore
impl !UnwindSafe for CredentialStore
impl Forget for CredentialStore
impl Move for CredentialStore
impl Send for CredentialStore
impl Sync for CredentialStore
impl Unpin for CredentialStore
impl UnsafeUnpin for CredentialStore
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§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