zone

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const EmptyPlaceholder = "placeholder"

EmptyPlaceholder will be used instead of empty ACME TXT because we cannot really set ""

Variables

View Source
var (
	ErrSoaNotFound    = errors.New("SOA not found")
	ErrRecordNotFound = errors.New("record not found")
	ErrNoMatchers     = errors.New("no record matchers provided")
	ErrOriginChanged  = errors.New("zone origin changed")
	ErrZoneNotFound   = errors.New("zone not found")
)

ErrSoaNotFound emited if zone file does not have SOA record, which is mandatory

Functions

func PrintEntries

func PrintEntries(entries []zonefile.Entry, w io.Writer)

func StripOrigin

func StripOrigin(name, origin string) string

Types

type Controller

type Controller interface {
	// ListZones returns all managed zones.
	ListZones(ctx context.Context) ([]ZoneSnapshot, error)
	// GetZone returns a managed zone by its origin name.
	GetZone(ctx context.Context, zoneName string) (ZoneSnapshot, error)
	// UpdateDDNSAddress changes DDNS A/AAAA records
	UpdateDDNSAddress(ctx context.Context, domain string, addrs []netip.Addr) error
	// UpdateACMEChallenge changes ACME TXT record for DNS-01 challenge
	UpdateACMEChallenge(ctx context.Context, domain string, newToken, oldToken string) error
	// ReplaceRRSet replaces or creates the requested RRSet in a specific zone.
	ReplaceRRSet(ctx context.Context, zoneName, name, typ string, ttl int, values []string) (changed bool, err error)
	// DeleteRRSet removes the requested RRSet from a specific zone.
	DeleteRRSet(ctx context.Context, zoneName, name, typ string) (changed bool, err error)
	// ZMUpdateRecord replace record values
	ZMUpdateRecord(ctx context.Context, domain string, typ string, ttl int, values []string) (changed bool, err error)
	// UpdatePTR updates PTR records for the given addresses in matching
	// reverse zones, pointing them to the target host. addresses must contain
	// at least one address; mode controls how the PTR records are managed.
	UpdatePTR(ctx context.Context, target string, addresses []netip.Addr, mode PTRUpdateMode) (changed bool, err error)
}

Controller implements zone file modification methods

func New

func New(zonefiles ...string) (Controller, error)

func NewWithOptions added in v0.14.0

func NewWithOptions(opts []Option, zonefiles ...string) (Controller, error)

type DomainCtrl

type DomainCtrl struct {
	// contains filtered or unexported fields
}

func (*DomainCtrl) DeleteRRSet added in v0.11.0

func (s *DomainCtrl) DeleteRRSet(ctx context.Context, zoneName, name, typ string) (changed bool, err error)

func (*DomainCtrl) GetZone added in v0.11.0

func (s *DomainCtrl) GetZone(ctx context.Context, zoneName string) (snapshot ZoneSnapshot, err error)

func (*DomainCtrl) ListZones added in v0.11.0

func (s *DomainCtrl) ListZones(ctx context.Context) ([]ZoneSnapshot, error)

func (*DomainCtrl) ReplaceRRSet added in v0.11.0

func (s *DomainCtrl) ReplaceRRSet(ctx context.Context, zoneName, name, typ string, ttl int, values []string) (changed bool, err error)

func (*DomainCtrl) UpdateACMEChallenge

func (s *DomainCtrl) UpdateACMEChallenge(ctx context.Context, domain string, newToken, oldToken string) (err error)

func (*DomainCtrl) UpdateDDNSAddress

func (s *DomainCtrl) UpdateDDNSAddress(ctx context.Context, domain string, addrs []netip.Addr) (err error)

func (*DomainCtrl) UpdatePTR added in v0.16.0

func (s *DomainCtrl) UpdatePTR(ctx context.Context, target string, addresses []netip.Addr, mode PTRUpdateMode) (changed bool, err error)

UpdatePTR updates PTR records for the requested addresses in matching reverse zones, pointing them to the target host. All addresses must have a matching reverse zone, otherwise ErrZoneNotFound is returned; when target, addresses set is empty or mode is invalid an error is returned without changes.

func (*DomainCtrl) ZMUpdateRecord added in v0.9.0

func (s *DomainCtrl) ZMUpdateRecord(ctx context.Context, domain string, typ string, ttl int, values []string) (changed bool, err error)

type File

type File struct {
	// contains filtered or unexported fields
}

func (*File) DeletePTRRecord added in v0.16.0

func (s *File) DeletePTRRecord(ctx context.Context, ptrName, target string) (changed bool, err error)

DeletePTRRecord removes the PTR record for ptrName pointing to target.

func (*File) DeleteRRSet added in v0.11.0

func (s *File) DeleteRRSet(ctx context.Context, name, typ string) (changed bool, err error)

func (*File) ReplaceRRSet added in v0.11.0

func (s *File) ReplaceRRSet(ctx context.Context, name, typ string, ttl int, values []string) (changed bool, err error)

func (*File) Snapshot added in v0.11.0

func (s *File) Snapshot(ctx context.Context) (snapshot ZoneSnapshot, err error)

func (*File) UpdateACMEChallenge

func (s *File) UpdateACMEChallenge(ctx context.Context, domain string, newToken, oldToken string) (err error)

func (*File) UpdateDDNSAddress

func (s *File) UpdateDDNSAddress(ctx context.Context, domain string, addrs []netip.Addr) error

func (*File) UpdatePTRAddress added in v0.16.0

func (s *File) UpdatePTRAddress(ctx context.Context, ptrName, target string, mode PTRUpdateMode) (changed bool, err error)

UpdatePTRAddress sets the PTR record for ptrName to target in the zone, according to mode:

  • append: insert the record only if it is missing, keeping existing PTRs;
  • replace: set a single PTR record in place, keeping unrelated PTRs on the same name;
  • replace-all: the PTR record set at that name becomes exactly {target}.

func (*File) ZMUpdateRecord added in v0.9.0

func (s *File) ZMUpdateRecord(ctx context.Context, domain string, typ string, ttl int, newValues []string) (changed bool, err error)

type Matcher added in v0.9.0

type Matcher struct {
	Domain []byte
	RRType uint16
	Values [][]byte
}

func (Matcher) Match added in v0.9.0

func (m Matcher) Match(e zonefile.Entry) bool

func (Matcher) String added in v0.9.0

func (m Matcher) String() string

type Matchers added in v0.9.0

type Matchers []Matcher

func (Matchers) Match added in v0.9.0

func (mm Matchers) Match(e zonefile.Entry) bool

type Option added in v0.14.0

type Option func(*DomainCtrl)

Option configures the zone controller.

func WithAcmeTTL added in v0.14.0

func WithAcmeTTL(ttl int) Option

WithAcmeTTL sets an explicit TTL (in seconds) for ACME challenge TXT records. If ttl is 0 (the default), no explicit TTL is written and the zone $TTL is used.

func WithDDNSManagePTR added in v0.16.0

func WithDDNSManagePTR(enable bool) Option

WithDDNSManagePTR enables updating PTR records in matching reverse zones on DDNS address updates. Reverse zones are matched by the reversed address name (in-addr.arpa / ip6.arpa); zones without a matching file are skipped.

type PTRUpdateMode added in v0.16.0

type PTRUpdateMode string

PTRUpdateMode controls how /zm/update-ptr manages PTR records for a target host across the requested addresses.

const (
	// PTRUpdateAppend only adds missing PTR records, never removes anything.
	PTRUpdateAppend PTRUpdateMode = "append"
	// PTRUpdateReplace sets the PTR record for each requested address in
	// place (single record per address, keeping unrelated PTRs on the name).
	PTRUpdateReplace PTRUpdateMode = "replace"
	// PTRUpdateReplaceAll makes the PTR set of the target exactly match the
	// requested addresses, removing stale PTR records pointing to the target.
	PTRUpdateReplaceAll PTRUpdateMode = "replace-all"
)

type RRSet added in v0.11.0

type RRSet struct {
	Name    string
	Type    string
	TTL     int
	Records []string
}

type ZoneSnapshot added in v0.11.0

type ZoneSnapshot struct {
	ID          string
	Name        string
	Serial      uint32
	RRsets      []RRSet
	Nameservers []string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL