SaltDns.Import (Salt v1.0.0)

Importing a zone: records from a transfer (SaltDns.Import.Axfr) or a zone file (SaltDns.Import.ZoneFile) in, a reviewable dry run and, on confirmation, one audited batch out.

The records are dns_erlang #dns_rr{} tuples. plan/4 is pure:

  1. Records of another class, outside the zone or with an unusable name are rejected with the reason.
  2. Records Salt DNS manages itself are managed: SOA anywhere, the apex NS, and the DNSSEC types (SaltDns.Zones.Validate.system_types/0). They are dropped and listed.
  3. Types Salt DNS does not carry (SaltDns.Zones.Rdata.types/0) are unsupported: dropped and listed with how many records each had.
  4. The rest is grouped into rrsets, rdata rendered to canonical text (SaltDns.Zones.Rdata.render/2) and run through SaltDns.Zones.Validate and SaltDns.Zones.Plan one rrset at a time. An rrset that fails (bad rdata, a CNAME conflict, DS at the apex, an apex CNAME) is rejected with its errors and the others carry on. Differing TTLs in one rrset become the lowest, and a TTL outside the organisation's bounds is clamped; both are warnings.
  5. The accepted operations applied to the current rrsets give the new state, and SaltDns.Zones.Diff the changes the import would make.

Nothing is dropped silently: every record read ends up in exactly one of the accepted rrsets, managed, unsupported or rejected (the report's counts add up to read).

Modes: :merge (default) leaves existing rrsets that the source does not mention alone; :replace deletes them (the zone becomes what the source says, apart from managed records; an rrset the source offered but that was rejected is deleted too, and is listed under rejected).

preview/3 loads the current rrsets and the organisation's TTL bounds; apply/3 writes the operations with SaltDns.Zones.apply_batch/3, audit source import. A preview is not a lock: apply/3 revalidates against the zone as it is then and may report errors.

Summary

Functions

Writes a previewed import in one transaction with one audit row (source import; the user and credential of actor are kept). Nothing is written when the report has no operations.

The zone's current rrsets in the shape plan/4 takes.

Plans an import. zone is the normalised zone name, records the source records and current the zone's rrsets ([] for a new zone). Options: :mode, :ttl_min, :ttl_max (organisation bounds), :default_ttl, and :replace - the record sets the operator chose to replace after seeing a conflict (%{name, type} maps or {name, type} tuples, as the report's conflicts lists them). Each is deleted in the same batch, so the import stays one audited change.

The dry run for importing records into zone: loads the zone's current rrsets and its organisation's TTL bounds, then plan/4.

Types

mode()

@type mode() :: :merge | :replace

Functions

apply(zone, report, actor)

@spec apply(
  SaltDns.Zones.Zone.t(),
  SaltDns.Import.Report.t(),
  SaltDns.Zones.Actor.t()
) ::
  {:ok, [SaltDns.Zones.Change.t()]}
  | {:error, {:invalid, [SaltDns.Zones.Error.t()]} | :zone_frozen}

Writes a previewed import in one transaction with one audit row (source import; the user and credential of actor are kept). Nothing is written when the report has no operations.

current_state(zone)

@spec current_state(SaltDns.Zones.Zone.t()) :: [SaltDns.Zones.Validate.rrset()]

The zone's current rrsets in the shape plan/4 takes.

plan(zone, records, current, opts \\ [])

Plans an import. zone is the normalised zone name, records the source records and current the zone's rrsets ([] for a new zone). Options: :mode, :ttl_min, :ttl_max (organisation bounds), :default_ttl, and :replace - the record sets the operator chose to replace after seeing a conflict (%{name, type} maps or {name, type} tuples, as the report's conflicts lists them). Each is deleted in the same batch, so the import stays one audited change.

preview(zone, records, opts \\ [])

The dry run for importing records into zone: loads the zone's current rrsets and its organisation's TTL bounds, then plan/4.