Kantoor.Provisioning.Domains (Kantoor v1.0.0)

Domains for the provisioning API. See Kantoor.Provisioning for tenancy, idempotency and suspension.

Kantoor has no organisation level: the domain is the unit of a customer. Its settings are the default mailbox quota, the retention and the seat limit (max_users).

The mail source

attach_mail_source/3 makes the instance's Karta deliver the domain's mail to Kantoor. It first calls Karta's health endpoint, so a Karta that cannot be reached is refused before anything is created; then it registers the endpoint and the route (both idempotent in Karta) and keeps the signing secret Karta shows once, encrypted in the vault. It needs the vault key, because that secret cannot be shown to the caller. Kantoor talks to one Karta (KARTA_BASE_URL, KARTA_API_KEY); the address and key of a Karta are not part of the call and are never returned.

Summary

Functions

Attaches the domain to the mail source. attrs["karta_domain_id"] is optional (the id Karta gave the domain). Repeating it returns the attachment that exists; asking for another karta_domain_id is :mail_source_conflict.

Deletes an empty domain. A domain that still has users or mailboxes is refused with their counts: delete those first. Deleting what is not there (or is not yours) is :ok, so a repeat is safe. The Karta route is put on hold.

The operator's domain by its reference, with settings; nil otherwise.

The operator's domains ordered by name. Options: :limit (default 100, at most

Creates the domain attrs["name"] under ref, or returns the one that exists. Settings given with it (default_quota_bytes, retention_days, max_users) apply on creation only; change them with update_settings/3.

Resumes the domain: ingest on, the route back to Kantoor, and the users that were disabled with it can sign in again. Users suspended on their own, or disabled by an admin, stay as they were.

Suspends the domain: ingest off, the Karta route on hold, its users disabled (the reason domain_suspended) and their sessions ended. Repeating it changes nothing but tries the route again. {:ok, domain, mail_source} where mail_source is :ok, :skipped (no route recorded) or :failed.

Changes the settings that are in attrs (default_quota_bytes, retention_days, max_users; null clears one). Raising a quota releases held mail that now fits.

Types

error()

@type error() ::
  :not_found
  | :ref_conflict
  | :name_taken
  | {:invalid, String.t(), String.t()}
  | Ecto.Changeset.t()

Functions

attach_mail_source(key, ref, attrs)

@spec attach_mail_source(Kantoor.ApiKeys.ApiKey.t(), String.t(), map()) ::
  {:ok, Kantoor.Mailboxes.Domain.t(), :attached | :existing} | {:error, term()}

Attaches the domain to the mail source. attrs["karta_domain_id"] is optional (the id Karta gave the domain). Repeating it returns the attachment that exists; asking for another karta_domain_id is :mail_source_conflict.

Errors: :domain_suspended, :vault_not_configured, :mail_source_not_configured, {:mail_source_unreachable, code} (the health call failed; nothing was created) and {:mail_source_refused, code} (Karta refused the registration; code is its error code or http_<status>).

delete(key, ref)

@spec delete(Kantoor.ApiKeys.ApiKey.t(), String.t()) ::
  :ok
  | {:error,
     {:not_empty, %{users: non_neg_integer(), mailboxes: non_neg_integer()}}}

Deletes an empty domain. A domain that still has users or mailboxes is refused with their counts: delete those first. Deleting what is not there (or is not yours) is :ok, so a repeat is safe. The Karta route is put on hold.

get(arg1, ref)

The operator's domain by its reference, with settings; nil otherwise.

list(api_key, opts \\ [])

The operator's domains ordered by name. Options: :limit (default 100, at most

  1. and :after (the last name of the previous page). Returns {rows, next} where next is the cursor for the following page or nil.

put(key, ref, attrs)

@spec put(Kantoor.ApiKeys.ApiKey.t(), String.t(), map()) ::
  {:ok, Kantoor.Mailboxes.Domain.t(), :created | :existing} | {:error, error()}

Creates the domain attrs["name"] under ref, or returns the one that exists. Settings given with it (default_quota_bytes, retention_days, max_users) apply on creation only; change them with update_settings/3.

{:ok, domain, :created | :existing}, {:error, :ref_conflict} (the reference names a domain with another name), {:error, :name_taken} (the name is attached already, to anyone) or a validation error.

resume(key, ref)

@spec resume(Kantoor.ApiKeys.ApiKey.t(), String.t()) ::
  {:ok, Kantoor.Mailboxes.Domain.t(), :ok | :skipped | :failed}
  | {:error, :not_found}

Resumes the domain: ingest on, the route back to Kantoor, and the users that were disabled with it can sign in again. Users suspended on their own, or disabled by an admin, stay as they were.

suspend(key, ref)

@spec suspend(Kantoor.ApiKeys.ApiKey.t(), String.t()) ::
  {:ok, Kantoor.Mailboxes.Domain.t(), :ok | :skipped | :failed}
  | {:error, :not_found}

Suspends the domain: ingest off, the Karta route on hold, its users disabled (the reason domain_suspended) and their sessions ended. Repeating it changes nothing but tries the route again. {:ok, domain, mail_source} where mail_source is :ok, :skipped (no route recorded) or :failed.

update_settings(key, ref, attrs)

@spec update_settings(Kantoor.ApiKeys.ApiKey.t(), String.t(), map()) ::
  {:ok, Kantoor.Mailboxes.Domain.t()}
  | {:error, :not_found | Ecto.Changeset.t()}

Changes the settings that are in attrs (default_quota_bytes, retention_days, max_users; null clears one). Raising a quota releases held mail that now fits.