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
impl OAuthTokenCache
Sourcepub fn insert_token(
&self,
auth: &OAuthAuth,
access_token: String,
expires_in: Option<u64>,
)
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
impl Debug for OAuthTokenCache
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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.