Kantoor. DnsRecords. Publishing
(Kantoor v1.0.0)
Keeps a mail domain's client-DNS records in Salt DNS, when Salt hosts the zone and the operator has said yes.
Check, publish, sync, stop
- check is read-only: finds the zone (the domain itself or an ancestor
Salt holds), reads its rrsets and classifies every record Kantoor expects
(
Kantoor.DnsRecords.Salt.State). It records the result on the domain's publication row, so the domain page can show the last state without calling Salt on every render. - publish sets the operator's yes and syncs.
- sync writes what the check found missing or different, removes values Kantoor wrote earlier that the current record set no longer wants, leaves every conflict alone, then checks again as the witness that the write landed.
- stop removes exactly the values recorded as Kantoor's own and clears the yes. A record that was already in the zone when Kantoor first looked is never removed.
The write path
Additions go in one POST /zones/:zone/import/apply (mode: merge) built by
Salt.State.zone_text/1, the batch API W116 added to Salt. An rrset that must
become empty is deleted with the rrset API, which the import API cannot
express. Ownership (Kantoor.DnsRecords.OwnedRecord) is recorded only for
values the import report says it added: a value that was already there
belongs to whoever put it there.
Failures
A zone the token cannot see is :not_hosted, not an error (Salt answers 404
for both "no such zone" and "another organisation's zone"). A transport
failure, a 401, a 5xx or a refused import is :error with a short reason; the
last successful report is kept, the new failure is stored in last_error.
Nothing is ever written to a zone whose check failed.
Summary
Functions
Read-only: what Salt holds against what Kantoor expects. Always returns
{:ok, result}; the status says whether the zone was found and usable.
The publication row of a domain, or nil.
The operator's yes: enable the publication and sync now. When the sync fails after enabling, the yes stays (the next nightly run retries); the error is returned with it.
Enables or disables automatic syncing without touching DNS.
Stops publishing: removes the values Kantoor wrote and clears the yes.
Writes the records that are missing or different and removes stale owned
values, then checks again. {:error, reason} when the zone is not usable or
Salt refused the write; nothing is claimed written then.
The nightly job and the domain-change hook: sync every enabled publication.
Returns {synced, failed}; one domain's failure never stops the others.
Types
@type result() :: %{ status: :ok | :attention | :not_hosted | :not_configured | :error, zone: String.t() | nil, entries: [Kantoor.DnsRecords.Salt.State.entry()], counts: map(), enabled: boolean(), error: term() | nil }
Functions
@spec check(Kantoor.Mailboxes.Domain.t()) :: {:ok, result()}
Read-only: what Salt holds against what Kantoor expects. Always returns
{:ok, result}; the status says whether the zone was found and usable.
@spec publication(Ecto.UUID.t()) :: Kantoor.DnsRecords.Publication.t() | nil
The publication row of a domain, or nil.
@spec publish(Kantoor.Mailboxes.Domain.t(), keyword()) :: {:ok, map()} | {:error, term(), Kantoor.DnsRecords.Publication.t()}
The operator's yes: enable the publication and sync now. When the sync fails after enabling, the yes stays (the next nightly run retries); the error is returned with it.
@spec set_publication(Kantoor.Mailboxes.Domain.t(), boolean()) :: Kantoor.DnsRecords.Publication.t()
Enables or disables automatic syncing without touching DNS.
@spec stop(Kantoor.Mailboxes.Domain.t()) :: {:ok, map()} | {:error, term()}
Stops publishing: removes the values Kantoor wrote and clears the yes.
The yes is cleared only after the removal succeeded. When Salt cannot be reached nothing was removed and the operator can try again; a half-stopped domain (yes off, records stranded) is the state this avoids.
@spec sync(Kantoor.Mailboxes.Domain.t(), keyword()) :: {:ok, map()} | {:error, term()}
Writes the records that are missing or different and removes stale owned
values, then checks again. {:error, reason} when the zone is not usable or
Salt refused the write; nothing is claimed written then.
@spec sync_all() :: {non_neg_integer(), non_neg_integer()}
The nightly job and the domain-change hook: sync every enabled publication.
Returns {synced, failed}; one domain's failure never stops the others.