Skip to main content

OAuthTokenCache

Struct OAuthTokenCache 

Source
pub struct OAuthTokenCache { /* private fields */ }
Expand description

The in-run OAuth token cache: acquired (or failed) tokens, keyed by [CacheKey], shared by every request in one sendra invocation that resolves the same oauth: config.

Scoped to one run, never persisted. See the module doc comment. Built once per invocation — in sendra-cli, alongside the one HttpClient the whole run shares — and, under --repeat, deliberately outlives every pass rather than being rebuilt per iteration: a --repeat 5 run is still one invocation, and the waste this cache exists to eliminate — a token request on every single call — would otherwise resurface once per pass instead of once for the run. This is the same reasoning that keeps the shared HttpClient across passes; it is the per-pass capture store, and (when --cookie-jar is set) the client’s cookie jar, that are deliberately reset instead, because captures and cookies are meant to model one fresh run each time, while re-authenticating every pass is exactly the waste this cache exists to eliminate.

A failed acquisition is cached too, and is not retried. Once a given oauth: config has failed once in this run, every later request sharing it fails immediately with the same reason rather than hitting the token endpoint again. A broken config (bad credentials, a typo’d token_url, an endpoint that is genuinely down) is not going to fix itself between one request and the next within the same invocation — retrying it for every request in a large collection would only hammer an endpoint that has already said no, and would queue the run’s other, unrelated failures behind a string of repeated timeouts. The cost is that a config which failed on a one-off transient blip (a dropped connection, a token server mid-restart) stays failed for the rest of this run — but the fix there is simply running sendra again, which is cheap, whereas there is no cheap way to walk back having hammered a struggling endpoint once per request instead of once.

Implementations§

Source§

impl OAuthTokenCache

Source

pub fn new() -> Self

Source§

impl OAuthTokenCache

Source

pub fn insert_token( &self, auth: &OAuthAuth, access_token: String, expires_in: Option<u64>, )

Records a token acquired outside the ordinary acquire_token path — the one case that needs this is an authorization_code login completed interactively (see the module doc comment), whose caller exchanged a code for a token itself via exchange_authorization_code and now wants every later request sharing this exact oauth: config to reuse it instead of asking the human to log in again.

Keyed and stored exactly like a token acquire_token acquired itself — same [CacheKey], same expiry-margin handling — so from acquire_token’s perspective afterward there is no difference between a token it fetched and one handed to it this way.

Trait Implementations§

Source§

impl Debug for OAuthTokenCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Deliberately never prints a cached access token — only how many entries exist. sendra-tui’s AppState derives Debug (used only for assert_eq!/panic messages in its own tests, never logged), and this cache is one of its fields; a token leaking into a debug print anywhere would defeat the whole “never persisted, never written anywhere but this in-memory cache” guarantee the module doc comment makes.

Source§

impl Default for OAuthTokenCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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<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