Karta. Provisioning
(Karta v1.0.0)
What an external system does through the provisioning API
(KartaWeb.Provisioning) to set a customer up: an organisation named by
the system's own reference, with a mail server to send from. Karta
knows nothing about the system; the reference is an opaque text.
Every operation is idempotent and safe to repeat: the reference (and, further down an organisation, a domain name or a credential's reference) is the natural key, and a request for what exists returns it. Operations on one organisation are serialised with a transaction-level advisory lock, so two identical requests at the same moment make one record.
put_organisation/2makes the organisation (and its mail server, named "Default") or returns it, renaming it when the name differs.- An organisation made here starts restricted (
Karta.Quotas) with a daily limit and a per-recipient limit (default_limits/0), so a new customer can send only low-volume transactional mail until the system lifts that withput_limits/2. suspend/2andresume/1stop and restart all sending: the organisation's servers are suspended (their credentials are refused, queued mail waits), the way a server's own suspension works (Karta.Servers). Resuming lifts only the suspensions the organisation's own made.delete/1ends the organisation: sending stops, credentials are revoked, webhooks are switched off, domains are removed and the reference is free again. The organisation's mail is kept until retention removes it, and the organisation no longer shows anywhere.
Summary
Functions
What a new organisation starts with: restricted, 100 recipients a day, 10
messages a day to one recipient. Set with config :karta, Karta.Provisioning, defaults: [daily_send_limit: ..., per_recipient_daily_limit: ...]
for another instance-wide start.
Ends the organisation (see the module doc). :ok also when there is
nothing to end.
The organisation with this reference, or nil (a deleted one is gone).
The trust level and limits of the organisation, with what it has sent today.
Sets the trust level and limits named in attrs (trust_level,
daily_send_limit, per_recipient_daily_limit; a limit of nil
removes it); what is left out stays. Repeating it changes nothing.
Makes the organisation with this reference, or returns it. attrs: the
name (required; it renames an existing organisation). Returns
{:ok, :created | :existing, organisation}.
Lifts the suspension: the servers it suspended send again and queued mail goes out.
The organisation's mail server, the one provisioning made. Credentials, webhooks and limits belong to it.
Suspends sending for the organisation, for reason (at most 230
characters; the organisation sees it). Suspending a suspended
organisation changes only the reason.
Runs fun holding the advisory lock of the reference, in a transaction.
Functions
@spec default_limits() :: map()
What a new organisation starts with: restricted, 100 recipients a day, 10
messages a day to one recipient. Set with config :karta, Karta.Provisioning, defaults: [daily_send_limit: ..., per_recipient_daily_limit: ...]
for another instance-wide start.
@spec delete(String.t()) :: :ok
Ends the organisation (see the module doc). :ok also when there is
nothing to end.
@spec get_organisation(String.t()) :: Karta.Accounts.Organisation.t() | nil
The organisation with this reference, or nil (a deleted one is gone).
@spec limits(Karta.Accounts.Organisation.t()) :: map()
The trust level and limits of the organisation, with what it has sent today.
@spec put_limits(Karta.Accounts.Organisation.t(), map()) :: {:ok, map()} | {:error, Ecto.Changeset.t()}
Sets the trust level and limits named in attrs (trust_level,
daily_send_limit, per_recipient_daily_limit; a limit of nil
removes it); what is left out stays. Repeating it changes nothing.
@spec put_organisation(String.t(), map()) :: {:ok, :created | :existing, Karta.Accounts.Organisation.t()} | {:error, Ecto.Changeset.t()}
Makes the organisation with this reference, or returns it. attrs: the
name (required; it renames an existing organisation). Returns
{:ok, :created | :existing, organisation}.
@spec resume(Karta.Accounts.Organisation.t()) :: {:ok, Karta.Accounts.Organisation.t()}
Lifts the suspension: the servers it suspended send again and queued mail goes out.
@spec server(Karta.Accounts.Organisation.t()) :: Karta.Servers.Server.t()
The organisation's mail server, the one provisioning made. Credentials, webhooks and limits belong to it.
@spec suspend(Karta.Accounts.Organisation.t(), String.t() | nil) :: {:ok, Karta.Accounts.Organisation.t()} | {:error, Ecto.Changeset.t()}
Suspends sending for the organisation, for reason (at most 230
characters; the organisation sees it). Suspending a suspended
organisation changes only the reason.
Runs fun holding the advisory lock of the reference, in a transaction.