SaltDns.Provisioning (Salt v1.0.0)

What an external provisioning system needs from Salt DNS, and nothing about that system in return.

A provisioning token (an API token created with provisioning: true by an owner or admin of an organisation, the provider) manages the child organisations of its provider: one per customer, named by the caller's own reference (external_ref, any string it chooses such as a customer id). Inside a child organisation the token may do everything the REST API offers on zones, records, names and imports. It cannot act in its provider organisation, in any other organisation, or on users and credentials (the API has no calls for those). The scope is decided by SaltDnsWeb.API.Authenticate: the child is named in the X-Salt-Organisation header, and an organisation that is not a child of the token's provider is the same 404 as one that does not exist.

Everything here is idempotent: put_child/3 called again with the same reference answers with the same organisation.

Summary

Functions

The credential as the access policy sees it while it works in child: the child's organisation and the grants of a provisioning token. The stored credential is not changed.

Every zone of every customer of parent as {customer, zone}, for the provider's own zone list. Owners and admins only; [] for anybody else.

Creates a provisioning token for organisation (a console action of an owner or admin). Returns the credential and the plaintext token, shown once. Option: :expires_at.

Deletes a child organisation that has no zones; {:error, :not_empty} otherwise.

The child organisation of parent_id with this reference, or nil.

One zone of a customer, to read: {:ok, customer, zone}. {:error, :forbidden} when the actor is not owner or admin of parent, {:error, :not_found} for a customer that is not a child of parent or a zone it does not have.

The children of a provider organisation, by reference.

The zones of one customer, each as %{zone, records, changed_at} (record count and the time of the last change), for an owner or admin of parent.

The customers of parent with their zone count, for an owner or admin of parent: {:ok, [%{organisation: org, zones: n}]} or {:error, :forbidden}.

The provisioning tokens of an organisation, newest first.

Creates the child organisation for ref, or returns the one that exists (and renames it when attrs has a different name). {:ok, organisation, :created | :existing}, or {:error, changeset} for a bad name.

True when ref is an acceptable external reference.

Functions

acting_in(credential, organisation)

The credential as the access policy sees it while it works in child: the child's organisation and the grants of a provisioning token. The stored credential is not changed.

all_customer_zones(actor, parent)

Every zone of every customer of parent as {customer, zone}, for the provider's own zone list. Owners and admins only; [] for anybody else.

create_token(organisation, user, name, opts \\ [])

Creates a provisioning token for organisation (a console action of an owner or admin). Returns the credential and the plaintext token, shown once. Option: :expires_at.

delete_child(organisation)

@spec delete_child(SaltDns.Accounts.Organisation.t()) :: :ok | {:error, :not_empty}

Deletes a child organisation that has no zones; {:error, :not_empty} otherwise.

get_child(parent_id, ref)

@spec get_child(integer(), String.t()) :: SaltDns.Accounts.Organisation.t() | nil

The child organisation of parent_id with this reference, or nil.

get_customer_zone(actor, parent, child_id, name)

@spec get_customer_zone(
  SaltDns.Access.actor(),
  SaltDns.Accounts.Organisation.t(),
  integer(),
  String.t()
) ::
  {:ok, SaltDns.Accounts.Organisation.t(), SaltDns.Zones.Zone.t()}
  | {:error, :forbidden | :not_found}

One zone of a customer, to read: {:ok, customer, zone}. {:error, :forbidden} when the actor is not owner or admin of parent, {:error, :not_found} for a customer that is not a child of parent or a zone it does not have.

list_children(parent_id)

@spec list_children(integer()) :: [SaltDns.Accounts.Organisation.t()]

The children of a provider organisation, by reference.

list_customer_zones(actor, parent, child_id)

@spec list_customer_zones(
  SaltDns.Access.actor(),
  SaltDns.Accounts.Organisation.t(),
  integer()
) ::
  {:ok, SaltDns.Accounts.Organisation.t(), [map()]}
  | {:error, :forbidden | :not_found}

The zones of one customer, each as %{zone, records, changed_at} (record count and the time of the last change), for an owner or admin of parent.

list_customers(actor, parent)

@spec list_customers(SaltDns.Access.actor(), SaltDns.Accounts.Organisation.t()) ::
  {:ok,
   [
     %{
       organisation: SaltDns.Accounts.Organisation.t(),
       zones: non_neg_integer()
     }
   ]}
  | {:error, :forbidden}

The customers of parent with their zone count, for an owner or admin of parent: {:ok, [%{organisation: org, zones: n}]} or {:error, :forbidden}.

list_tokens(organisation)

The provisioning tokens of an organisation, newest first.

put_child(organisation, ref, attrs)

@spec put_child(SaltDns.Accounts.Organisation.t(), String.t(), map()) ::
  {:ok, SaltDns.Accounts.Organisation.t(), :created | :existing}
  | {:error, Ecto.Changeset.t()}

Creates the child organisation for ref, or returns the one that exists (and renames it when attrs has a different name). {:ok, organisation, :created | :existing}, or {:error, changeset} for a bad name.

valid_ref?(ref)

@spec valid_ref?(term()) :: boolean()

True when ref is an acceptable external reference.