Karta.Webhooks.Webhook (Karta v1.0.0)

A server's webhook: where its events go (url), in which format (format, Karta.Webhooks.Format; chosen when it is added), and which (events, a list of the format's types; nil for every type the format has, those added later included).

secret signs every request (Karta.Webhooks.Signature, or the format's signature: in SendGrid's format it is the private key of the webhook's key pair); after a rotation previous_secret signs too, until previous_secret_expires_at (Standard Webhooks only). Both are encrypted by Karta.Vault.

A URL may be given with a user name and password (https://user:password@host/..., as Postal's, Mailgun's and Postmark's webhooks allow): only with https:. They are taken out of url and kept in credentials ("user:password", decoded, encrypted by Karta.Vault); every request sends them as Basic authentication. Changing the URL replaces them (a URL without them removes them).

enabled is false when someone switched the webhook off, or when Karta did (disabled_reason: "failing", at disabled_at): its requests had failed since failing_since for too long (Karta.Webhooks.Sender).

auth_header and auth_header_value are an extra header that authenticates every request, for a receiver that cannot check a signature (Karta.RequestAuth); the value is encrypted by Karta.Vault and shown once. The header is sent beside the format's signature, never instead of it.

Summary

Functions

A URL as a webhook keeps it: trimmed, without a user name and password.

What input may set: the name, the URL, the events and whether it is enabled; the format too while the webhook is new. allow_http: true accepts http: URLs (otherwise only https:).

The user name the webhook's requests authenticate with, or nil.

Types

t()

@type t() :: %Karta.Webhooks.Webhook{
  __meta__: term(),
  auth_header: term(),
  auth_header_remove: term(),
  auth_header_value: term(),
  credentials: term(),
  disabled_at: term(),
  disabled_reason: term(),
  enabled: term(),
  events: term(),
  failing_since: term(),
  format: term(),
  id: term(),
  inserted_at: term(),
  name: term(),
  previous_secret: term(),
  previous_secret_expires_at: term(),
  secret: term(),
  server: term(),
  server_id: term(),
  updated_at: term(),
  url: term()
}

Functions

bare_url(url)

@spec bare_url(String.t()) :: String.t()

A URL as a webhook keeps it: trimmed, without a user name and password.

changeset(webhook, attrs, opts \\ [])

@spec changeset(t(), map(), keyword()) :: Ecto.Changeset.t()

What input may set: the name, the URL, the events and whether it is enabled; the format too while the webhook is new. allow_http: true accepts http: URLs (otherwise only https:).

user(webhook)

@spec user(t()) :: String.t() | nil

The user name the webhook's requests authenticate with, or nil.