AshVault.Macaroon.Ttl behaviour (AshVault v0.2.0)

Copy Markdown View Source

Behaviour for a dynamic default_ttl: the lifetime of a token, decided at mint time.

default_ttl MyApp.Macaroons.TtlByPlan
default_ttl {MyApp.Macaroons.TtlByPlan, enterprise: 90 * 86_400}
default_ttl fn input -> if input.tenant == "internal", do: 86_400, else: 3_600 end
max_ttl 90 * 86_400

ttl/2 receives the mint action's Ash.ActionInput (tenant, actor via input.context.private.actor, arguments) and returns seconds or :infinity.

A dynamic default_ttl requires a static max_ttl, and the result is always clamped to it — a function can never mint a token that outlives max_ttl, whatever it returns. A result that is neither a positive integer nor :infinity, or a raise, refuses the mint.

Summary

Callbacks

The lifetime, in seconds, of the token being minted.

Callbacks

ttl(input, opts)

@callback ttl(input :: Ash.ActionInput.t(), opts :: keyword()) ::
  pos_integer() | :infinity

The lifetime, in seconds, of the token being minted.