SaltDns. Zones
(Salt v1.0.0)
Zones and their records.
Every function that changes data does so in one database transaction that
also writes one row to the changes audit table, and returns the list of
SaltDns.Zones.Change it caused, in the order the Knot bridge should apply
them. Zone-level changes (creating a zone, changing its settings) cause no
record changes and return [].
Writes to one zone are serialised with a row lock on the zone, so two concurrent writers see each other's results and the diffs stay correct.
Rrset input and its validation are described in SaltDns.Zones.Validate.
Validation failures are {:error, {:invalid, [SaltDns.Zones.Error.t()]}};
nothing is written in that case, not even an audit row. Authorisation is
not checked here: this context is an internal layer, and every request
path (API, UI, RFC 2136) must call SaltDns.Access before it.
Summary
Functions
Applies several operations all together or not at all, with one audit row.
apply_batch/3 for a zone already locked by with_locked_zone/2 (it does
not open a transaction). A validation error writes nothing and is returned
as a value, so the caller can still commit its own result.
A zone changeset for forms.
Creates a zone (status pending unless given) in an organisation.
Deletes one rrset. Takes the :precondition option of put_rrset/4.
Deletes a zone and its records. Returns the removal of every served record.
The zone as an RFC 1035 master file. See SaltDns.Zones.Export.
One audit entry of the zone by id (an integer or its text), or nil.
Gets one rrset with its records, or nil. The name and type are normalised first.
Gets a zone by id. Raises Ecto.NoResultsError.
The zone called name in an organisation, or nil (names are normalised
first). A disabled zone is found only when the organisation has no live one.
The audit entries of a zone, newest first.
All rrsets of a zone with their records, ordered by name and type.
Lists the zones of an organisation by name.
Gets the zones with a name (any form SaltDns.Zones.Name accepts).
Creates or replaces one rrset.
Puts the zone back as it was before an audited batch: applies the inverse
recorded with that batch as one new batch, with one audit row (rrset.undo).
The entry must belong to this zone. An entry without an inverse (a zone
setting, a single rrset, a change from before inverses were kept) is
{:error, :no_inverse}.
Updates a zone's status, DNSSEC settings, default TTL or SOA timers.
Runs fun with the zone locked (FOR UPDATE) in one database transaction.
Types
@type invalid() :: {:invalid, [SaltDns.Zones.Error.t()]} | :precondition_failed
@type op() :: SaltDns.Zones.Plan.op()
Functions
@spec apply_batch(SaltDns.Zones.Zone.t(), [op()], SaltDns.Zones.Actor.t()) :: {:ok, [SaltDns.Zones.Change.t()]} | {:error, invalid()}
Applies several operations all together or not at all, with one audit row.
Operations are {:put, attrs} and {:delete, name, type}, applied in
order. Error paths start with the index of the operation.
The audit row keeps the inverse of the batch (AuditEntry.inverse), so
undo/3 can put the zone back as it was.
@spec apply_batch_locked(SaltDns.Zones.Zone.t(), [op()], SaltDns.Zones.Actor.t()) :: {:ok, [SaltDns.Zones.Change.t()]} | {:error, invalid()}
apply_batch/3 for a zone already locked by with_locked_zone/2 (it does
not open a transaction). A validation error writes nothing and is returned
as a value, so the caller can still commit its own result.
@spec change_zone(SaltDns.Zones.Zone.t(), map(), SaltDns.Accounts.Organisation.t()) :: Ecto.Changeset.t()
A zone changeset for forms.
@spec create_zone(SaltDns.Accounts.Organisation.t(), map(), SaltDns.Zones.Actor.t()) :: {:ok, SaltDns.Zones.Zone.t(), [SaltDns.Zones.Change.t()]} | {:error, Ecto.Changeset.t()}
Creates a zone (status pending unless given) in an organisation.
Deletes one rrset. Takes the :precondition option of put_rrset/4.
@spec delete_zone(SaltDns.Zones.Zone.t(), SaltDns.Zones.Actor.t()) :: {:ok, [SaltDns.Zones.Change.t()]}
Deletes a zone and its records. Returns the removal of every served record.
@spec export(SaltDns.Zones.Zone.t()) :: String.t()
The zone as an RFC 1035 master file. See SaltDns.Zones.Export.
@spec get_audit_entry(SaltDns.Zones.Zone.t(), term()) :: SaltDns.Zones.AuditEntry.t() | nil
One audit entry of the zone by id (an integer or its text), or nil.
@spec get_rrset(SaltDns.Zones.Zone.t(), String.t(), String.t()) :: SaltDns.Zones.Rrset.t() | nil
Gets one rrset with its records, or nil. The name and type are normalised first.
@spec get_zone!(integer()) :: SaltDns.Zones.Zone.t()
Gets a zone by id. Raises Ecto.NoResultsError.
@spec get_zone_by_name(integer(), String.t()) :: SaltDns.Zones.Zone.t() | nil
The zone called name in an organisation, or nil (names are normalised
first). A disabled zone is found only when the organisation has no live one.
@spec list_audit(SaltDns.Zones.Zone.t(), map() | keyword()) :: %{ entries: [SaltDns.Zones.AuditEntry.t()], next: integer() | nil }
The audit entries of a zone, newest first.
Filters (map or keyword): :source (an audit source), :action,
:since, :until (DateTime, inclusive), :limit (default 50, at most
- and
:before(an entry id: only older entries). Returns the entries and the:beforevalue for the next page (nil on the last page).
@spec list_rrsets(SaltDns.Zones.Zone.t()) :: [SaltDns.Zones.Rrset.t()]
All rrsets of a zone with their records, ordered by name and type.
@spec list_zones(SaltDns.Accounts.Organisation.t()) :: [SaltDns.Zones.Zone.t()]
Lists the zones of an organisation by name.
@spec list_zones_by_name(String.t()) :: [SaltDns.Zones.Zone.t()]
Gets the zones with a name (any form SaltDns.Zones.Name accepts).
Creates or replaces one rrset.
Option :precondition (checked under the zone lock, so it is atomic with
the write): :exists, :absent or {:etag, if_match_header}; a failed
check is {:error, :precondition_failed} and nothing is written.
@spec undo( SaltDns.Zones.Zone.t(), SaltDns.Zones.AuditEntry.t(), SaltDns.Zones.Actor.t() ) :: {:ok, [SaltDns.Zones.Change.t()]} | {:error, invalid() | :no_inverse}
Puts the zone back as it was before an audited batch: applies the inverse
recorded with that batch as one new batch, with one audit row (rrset.undo).
The entry must belong to this zone. An entry without an inverse (a zone
setting, a single rrset, a change from before inverses were kept) is
{:error, :no_inverse}.
@spec update_zone(SaltDns.Zones.Zone.t(), map(), SaltDns.Zones.Actor.t()) :: {:ok, SaltDns.Zones.Zone.t(), [SaltDns.Zones.Change.t()]} | {:error, Ecto.Changeset.t() | :zone_frozen}
Updates a zone's status, DNSSEC settings, default TTL or SOA timers.
@spec with_locked_zone(SaltDns.Zones.Zone.t(), (SaltDns.Zones.Zone.t() -> {:ok, term()} | {:error, term()})) :: {:ok, term()} | {:error, term()}
Runs fun with the zone locked (FOR UPDATE) in one database transaction.
fun receives the zone as just read under the lock and must return
{:ok, value} or {:error, reason}; an error rolls everything back. Inside
fun, read the zone with list_rrsets/1, decide, and write with
apply_batch_locked/3: no other writer of this zone can run in between, so a
check made from what was read still holds when the write happens (RFC 2136
section 3.7). Returns {:error, :not_found} when the zone is gone.