EndPointBlank.AccessTokens (end_point_blank_elixir v0.6.0)

Copy Markdown

In-process cache of this node's access tokens, one per application environment.

A token is cached under the canonical base URL intake resolved the request to -- not under the URL the caller supplied. A caller asks for the URL it is about to call; intake answers with the base URL of the environment that URL belongs to, and subsequent calls anywhere under that base URL reuse the entry. A node that calls several targets therefore holds several tokens.

Lookup is a plain exact-or-path-prefix comparison, with the longest match winning. The SDK deliberately does not normalize: intake owns that rule, and a miss costs one extra request rather than a wrong answer.

All reads and writes go through this GenServer's mailbox, so they are fully serialized -- unlike the Python and Ruby ports, there is no lock-free fast path here for a concurrent write to race, so this holds a plain map and mutates it directly. Do not add copy-on-write; there is nothing here for it to protect.

Tokens are proactively refreshed when they are within two minutes of expiry to avoid serving one that dies in flight -- an expired token can never be revived, only replaced.

Summary

Functions

Returns a specification to start this module under a supervisor.

Discards every held token.

Returns true if a token covering base_url is held and not about to expire.

Discards a held token, but only if it is still the one the caller had.

Returns a valid access token for base_url, minting one if no usable entry covers it.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear()

Discards every held token.

exists?(base_url)

Returns true if a token covering base_url is held and not about to expire.

invalidate(stale_token)

Discards a held token, but only if it is still the one the caller had.

Every request in flight when a token is rejected reports the same stale value. Only the first of them should cause a mint — the rest are holding a token that has already been replaced, and clearing on their behalf would discard a good token and stampede intake.

The lookup is by token value because a rejected caller has a token, not a base_url.

start_link(opts)

token(base_url)

Returns a valid access token for base_url, minting one if no usable entry covers it.

base_url is the URL you are about to call, with any query string and fragment removed. It is sent verbatim; intake normalizes it and matches it against registered base URLs by longest path prefix.

Returns nil rather than raising if a token cannot be produced -- which includes a response that carried a token but no base_url (nothing to cache it under) as well as the cache failing to answer in time -- so an intake outage costs the caller a fall back to Basic rather than its request.