SaltDns.Proxy.AddressPlan (Salt v1.0.0)

Which address records a proxy group should have in the zones, and what to write to get there. Pure: the caller reads the zone and the ownership rows and applies the operations (SaltDns.Proxy.Addresses).

The names

The group's address names are the hosts of its routes that have publish_address on, plus the extra names added to the group. A wildcard route *.x.example.org is the record *.x.example.org. A name is placed in the zone with the longest matching name (locate/2); a name in no zone of the organisation is not an address name when it comes from a route and is shown as refused when it was added by hand.

Safety

The plan never touches what it did not write:

  • Ownership is a row per (zone, name, type) naming the group and the records written (SaltDns.Proxy.PublishedRecord). A record set counts as ours only while its records are still exactly those, with none disabled. Anyone who edited it owns it from then on.
  • A name with an A, AAAA or CNAME record set that is not ours is a conflict: nothing at that name is written, merged or removed, and the conflict reports what is there.
  • A name at or below a delegation inside the zone (an NS record set below the apex) is refused. The apex itself is allowed.
  • A name that is no longer wanted (route removed, flag off, extra name removed, setting off) loses exactly the record sets that are ours.

Summary

Functions

True when name is at or below a delegation of the zone: an NS record set at a name below the apex that is the name or one of its parents. rrsets is the zone's record sets keyed by {name, type}.

The zone with the longest name that holds name, or nil.

The address names of a group: [%{name:, sources: [:route | :extra]}], sorted. routes are maps with host and publish_address; extras are names.

The plan for one zone.

Types

ownership()

@type ownership() :: %{
  optional({String.t(), String.t()}) => %{
    group_id: integer(),
    records: [String.t()]
  }
}

rrsets()

@type rrsets() :: %{
  optional({String.t(), String.t()}) => %{ttl: integer(), records: [map()]}
}

status()

@type status() ::
  {:published, %{required(String.t()) => [String.t()]}}
  | {:unchanged, %{required(String.t()) => [String.t()]}}
  | {:conflict, [map()]}
  | {:refused, :delegation | :outside_zone}

zone()

@type zone() :: %{id: integer(), name: String.t()}

Functions

delegated?(name, zone_name, rrsets)

@spec delegated?(String.t(), String.t(), rrsets()) :: boolean()

True when name is at or below a delegation of the zone: an NS record set at a name below the apex that is the name or one of its parents. rrsets is the zone's record sets keyed by {name, type}.

locate(name, zones)

@spec locate(String.t(), [zone()]) :: zone() | nil

The zone with the longest name that holds name, or nil.

names(routes, extras)

@spec names([map()], [String.t()]) :: [
  %{name: String.t(), sources: [:route | :extra]}
]

The address names of a group: [%{name:, sources: [:route | :extra]}], sorted. routes are maps with host and publish_address; extras are names.

plan_zone(args)

@spec plan_zone(map()) :: map()

The plan for one zone.

  • group_id, zone, rrsets, ownership (the rows of this zone)
  • wanted: the address names (names/2) that locate/2 put in this zone
  • desired: {:publish, %{"A" => [..], "AAAA" => [..]}} (from SaltDns.Proxy.Answer) or :keep_last
  • ttl: the TTL for the sets written

Returns %{statuses: %{name => status}, ops: [op], own: [{name, type}], release: [{name, type}]}. ops are the zone mutation operations (SaltDns.Zones); own are the sets to record as ours after writing them (the caller reads the stored records back), release the ownership rows to drop.