ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Credential.Refresh.Internal

Description

The implementation behind Ecluse.Core.Credential.Refresh, which documents the policy and re-exports the curated surface. Importing this module opts out of that stability promise, the convention text and bytestring use, so production code imports the public one.

Synopsis

Configuration

data RefreshConfig Source #

Refresh policy with injected mint, clock, jitter and observers.

Constructors

RefreshConfig 

Fields

defaultRefreshConfig :: RefreshConfig Source #

Default policy knobs. Unwired rcMint and rcClock throw Unconfigured.

The refreshing provider

refreshingProvider :: RefreshConfig -> IO CredentialProvider Source #

Build a cached provider, minting eagerly so an initial mint failure aborts construction.

refreshingProviderWith :: IO () -> RefreshConfig -> IO CredentialProvider Source #

Add a test hook between the single-flight claim and the mint runner.

Telemetry reporters

data RefreshReporter Source #

Observe refresh outcomes with the active token's absolute expiry, absent for non-expiring tokens.

Constructors

RefreshReporter 

Fields

noRefreshReporter :: RefreshReporter Source #

The inert refresh reporter: records nothing on either outcome.

data CredentialReporters Source #

The telemetry observers a refreshing provider records through, bundled into one value.

Constructors

CredentialReporters 

Fields

noCredentialReporters :: CredentialReporters Source #

The inert pair: a provider built with it records nothing on either signal.

Failure

data CredentialError Source #

A failure from credential minting or refresh policy.

Constructors

BreakerOpen

The token expired with the mint breaker open, so no mint was attempted.

Unconfigured Text

An effectful leaf still holds its defaultRefreshConfig placeholder.

MintedTokenAlreadyExpired

An already-expired mint is treated as a mint failure.

State and pure/transition helpers (exposed for direct testing)

data CacheState Source #

The mutable state of a refreshing provider.

Constructors

CacheState 

Fields

data MintClaim Source #

A mint identity and its atomically admitted breaker ticket.

Instances

Instances details
Show MintClaim Source # 
Instance details

Defined in Ecluse.Core.Credential.Refresh.Internal

Eq MintClaim Source # 
Instance details

Defined in Ecluse.Core.Credential.Refresh.Internal

data ServeAction Source #

Whether a caller serves the cache, owns a mint, or receives a breaker refusal.

Constructors

ServeCached AuthToken

Serve a valid cached token.

ServeAndRefresh AuthToken MintClaim

Serve the token and transfer the claim to a background worker.

MintNow MintClaim

Run the claimed mint synchronously for an expired token.

RefuseMint

Refuse an expired caller during cooldown or owned recovery.

decide :: TVar CacheState -> UTCTime -> STM ServeAction Source #

Claim mint and breaker ownership together. Healthy expired followers wait, recovery followers refuse.

refreshDueAt :: RefreshConfig -> UTCTime -> AuthToken -> IO (Maybe UTCTime) Source #

Jitter advances the refresh fraction. The floor bounds the latest instant before expiry.

onMintSuccess :: MintClaim -> AuthToken -> Maybe UTCTime -> CacheState -> CacheState Source #

Install a matching owner's token and settle its breaker. Cleanup releases the mint claim.

onMintFailure :: MintClaim -> RefreshConfig -> UTCTime -> CacheState -> CacheState Source #

Count a matching owner's genuine failure without replacing the cached token.

releaseSingleFlight :: TVar CacheState -> MintClaim -> IO () Source #

Release only this mint's ownership and its unsettled recovery ticket, on every exit.