# `AshVault.Macaroon.Caveat`
[🔗](https://github.com/jakeschurch/ash_vault/blob/main/lib/ash_vault/macaroon/caveat.ex#L1)

Behaviour for a caveat check: decides whether one caveat value admits the request.

    caveat :ip, :string, check: MyApp.Caveats.Ip
    caveat :ip, :string, check: {MyApp.Caveats.Ip, trust_proxy?: true}
    caveat :ip, :string, check: fn ip, ctx -> ctx.context[:remote_ip] == ip end

`c:check/3` returns `:ok` or `true` to admit, and anything else — `false`,
`{:error, reason}`, `nil` — to refuse. Refusal is the default for every answer that is
not an explicit yes.

## Checks must only narrow

Every caveat a token carries must admit the request, so appending a caveat can only
shrink what the token allows — **provided each check depends only on its own value
and the request**. A check must never widen access because of its value (an `admin:
true` caveat that grants more), and must never consult other caveats. That is what
makes `AshVault.Macaroon.attenuate/2` safe to hand to token holders.

A check that raises fails the request; it is not rescued.

# `check`

```elixir
@callback check(
  value :: term(),
  context :: AshVault.Macaroon.CheckContext.t(),
  opts :: keyword()
) ::
  :ok | boolean() | {:error, term()}
```

Decide whether `value` admits the request described by `context`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
