pub struct TokenCache { /* private fields */ }Expand description
Thread-safe cache of broker access tokens. Cloneable handle over shared state. Holds ONLY short-lived access tokens, never a refresh token, never persisted to disk.
Keys are either a bare provider id (legacy callers) or a scoped key built
by TokenCache::scoped_key: "<storage_key>|<source scope>", where
the scope identifies the broker endpoint AND the machine principal (a
digest of the machine token — never the token itself) so a re-pointed or
re-keyed client can never reuse another principal’s cached token.
Implementations§
Source§impl TokenCache
impl TokenCache
pub fn new() -> TokenCache
Sourcepub fn get_fresh(&self, provider: &str, margin_ms: u64) -> Option<BrokerToken>
pub fn get_fresh(&self, provider: &str, margin_ms: u64) -> Option<BrokerToken>
Return the cached token for provider only if present AND not within
margin_ms of expiry. Otherwise None (caller should fetch).
pub fn put(&self, provider: &str, token: BrokerToken)
Sourcepub fn invalidate(&self, provider: &str)
pub fn invalidate(&self, provider: &str)
Drop every cached token for provider — the legacy bare key and every
scoped (account, source) key of that provider — so a 401 or a source
switch can never leave an account’s stale token behind.
Sourcepub fn scoped_key(scope: &str, cred: &CredentialRef) -> String
pub fn scoped_key(scope: &str, cred: &CredentialRef) -> String
Cache key for one credential fetched from one source scope.
Sourcepub fn invalidate_credential(&self, scope: &str, cred: &CredentialRef)
pub fn invalidate_credential(&self, scope: &str, cred: &CredentialRef)
Drop the cached token for exactly one scoped credential.
Sourcepub fn get_unexpired(&self, provider: &str) -> Option<BrokerToken>
pub fn get_unexpired(&self, provider: &str) -> Option<BrokerToken>
Cached token if present and not PAST hard expiry (ignores the refetch margin). Used as a degraded-mode fallback when the broker is unreachable: a token slightly inside its refetch window is still better than failing.
Trait Implementations§
Source§impl Clone for TokenCache
impl Clone for TokenCache
Source§fn clone(&self) -> TokenCache
fn clone(&self) -> TokenCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TokenCache
Redacting Debug — print only the cached provider names, never the tokens.
impl Debug for TokenCache
Redacting Debug — print only the cached provider names, never the tokens.
Source§impl Default for TokenCache
impl Default for TokenCache
Source§fn default() -> TokenCache
fn default() -> TokenCache
Auto Trait Implementations§
impl Freeze for TokenCache
impl RefUnwindSafe for TokenCache
impl Send for TokenCache
impl Sync for TokenCache
impl Unpin for TokenCache
impl UnsafeUnpin for TokenCache
impl UnwindSafe for TokenCache
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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