models

package
v4.30.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 20 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// DomainTag is the key used to store a copy of DomainConfig.Tag in the Metadata map.
	DomainTag = "dnscontrol_tag"

	// DomainUniqueName is the key used to store a copy of DomainConfig.UniqueName in the Metadata map.
	DomainUniqueName = "dnscontrol_uniquename"

	// DomainNameRaw is the key used to store a copy of DomainConfig.NameRaw in the Metadata map.
	DomainNameRaw = "dnscontrol_nameraw"

	// DomainNameUnicode is the key used to store a copy of DomainConfig.NameUnicode in the Metadata map.
	DomainNameUnicode = "dnscontrol_nameunicode"
)
View Source
const DefaultTTL = uint32(300)

DefaultTTL is applied to any DNS record without an explicit TTL.

Variables

This section is empty.

Functions

func CanonicalizeTargets added in v4.1.1

func CanonicalizeTargets(recs []*RecordConfig, origin string)

CanonicalizeTargets turns Targets into FQDNs

func DecodeLuaPayload added in v4.27.0

func DecodeLuaPayload(payload string) (string, error)

DecodeLuaPayload normalizes the LUA payload for storage in RecordConfig.target.

func Downcase

func Downcase(recs []*RecordConfig)

Downcase converts all labels and targets to lowercase in a list of RecordConfig.

func FixPosition added in v4.26.0

func FixPosition(str string) string

FixPosition takes the string representation of a position in a file that comes from dnsconfig.js's initial execution, and reduces it down to just the line/position we display to the user. The input is not well-defined, thus if we find something we don't expect, we just return the original input. TODO: Move this to rtypecontrol or a similar package.

func MakeUnknown added in v4.8.1

func MakeUnknown(rc *RecordConfig, rtype string, contents string, origin string) error

MakeUnknown turns an RecordConfig into an UNKNOWN type.

func NameserversToStrings

func NameserversToStrings(nss []*Nameserver) (s []string)

NameserversToStrings constructs a list of strings from *Nameserver structs

func ParseLuaContent added in v4.27.0

func ParseLuaContent(content string) (rtype string, payload string)

ParseLuaContent splits a PowerDNS LUA record content string into its emitted rtype and payload.

func ParseQuotedFields

func ParseQuotedFields(s string) ([]string, error)

ParseQuotedFields is like strings.Fields except individual fields might be quoted using `"`.

func ParseQuotedTxt

func ParseQuotedTxt(s string) []string

ParseQuotedTxt returns the individual strings of a combined quoted string.

`foo`  -> []string{"foo"}
`"foo"` -> []string{"foo"}
`"foo" "bar"` -> []string{"foo", "bar"}
`"f"oo" "bar"` -> []string{`f"oo`, "bar"}

NOTE: It is assumed there is exactly one space between the quotes. NOTE: This doesn't handle escaped quotes. NOTE: You probably want to use ParseQuotedFields() for RFC 1035-compliant quoting.

func PostProcessRecords

func PostProcessRecords(recs []*RecordConfig)

PostProcessRecords does any post-processing of the downloaded DNS records. Deprecated. zonerecords.CorrectZoneRecords() calls Downcase directly.

func ReverseAltitude added in v4.28.0

func ReverseAltitude(packedAltitude uint32) float64

ReverseAltitude takes the packed altitude and returns the altitude in meters.

func ReverseENotationInt added in v4.28.0

func ReverseENotationInt(packedValue uint8) float64

ReverseENotationInt produces a number from a mantissa_exponent 4bits:4bits uint8

func ReverseLatitude added in v4.28.0

func ReverseLatitude(lat uint32) (string, uint8, uint8, float64)

ReverseLatitude takes the packed latitude and returns the hemisphere, degrees, minutes, and seconds.

func ReverseLongitude added in v4.28.0

func ReverseLongitude(lon uint32) (string, uint8, uint8, float64)

ReverseLongitude takes the packed longitude and returns the hemisphere, degrees, minutes, and seconds.

func StripQuotes

func StripQuotes(s string) string

StripQuotes returns the string with the starting and ending quotes removed. If it is not quoted, the original string is returned.

func WarnNameserverDot

func WarnNameserverDot(p, w string)

WarnNameserverDot prints a warning about issue 491 never more than once.

Types

type Correction

type Correction struct {
	F   func() error `json:"-"`
	Msg string
}

Correction is anything that can be run. Implementation is up to the specific provider.

type DNSConfig

type DNSConfig struct {
	Registrars         []*RegistrarConfig            `json:"registrars"`
	DNSProviders       []*DNSProviderConfig          `json:"dns_providers"`
	Domains            []*DomainConfig               `json:"domains"`
	RegistrarsByName   map[string]*RegistrarConfig   `json:"-"`
	DNSProvidersByName map[string]*DNSProviderConfig `json:"-"`
	SkipRecordAudit    bool                          `json:"skiprecordaudit,omitempty"`
}

DNSConfig describes the desired DNS configuration, usually loaded from dnsconfig.js.

func (*DNSConfig) FindDomain

func (config *DNSConfig) FindDomain(query string) *DomainConfig

FindDomain returns the *DomainConfig for domain query in config.

func (*DNSConfig) PostProcess added in v4.28.0

func (config *DNSConfig) PostProcess() error

PostProcess performs and post-processing required after running dnsconfig.js and loading the result.

type DNSProvider

type DNSProvider interface {
	GetNameservers(domain string) ([]*Nameserver, error)
	GetZoneRecords(domain string, meta map[string]string) (Records, error)
	GetZoneRecordsCorrections(dc *DomainConfig, existing Records) ([]*Correction, int, error)
}

DNSProvider is an interface for DNS Provider plug-ins.

type DNSProviderConfig

type DNSProviderConfig struct {
	Name     string          `json:"name"`
	Type     string          `json:"type"`
	Metadata json.RawMessage `json:"meta,omitempty"`
}

DNSProviderConfig describes a DNS service provider.

type DNSProviderInstance

type DNSProviderInstance struct {
	ProviderBase
	Driver              DNSProvider
	NumberOfNameservers int
}

DNSProviderInstance is a single DNS provider.

type DomainConfig

type DomainConfig struct {
	NameRaw     string `json:"-"`    // name as entered by user in dnsconfig.js
	Name        string `json:"name"` // NO trailing "."   Converted to IDN (punycode) early in the pipeline.
	NameUnicode string `json:"-"`    // name in Unicode format

	Tag         string `json:"tag,omitempty"` // Split horizon tag.
	UniqueName  string `json:"uniquename"`    // .Name + "!" + .Tag (no !tag added if tag is "")
	DisplayName string `json:"-"`             // For TUI display: "canonical!tag" or "canonical!tag (unicode)"

	RegistrarName    string         `json:"registrar"`
	DNSProviderNames map[string]int `json:"dnsProviders"`

	Metadata         map[string]string `json:"meta,omitempty"`
	Records          Records           `json:"records"`
	Nameservers      []*Nameserver     `json:"nameservers,omitempty"`
	NameserversMutex sync.Mutex        `json:"-"`

	EnsureAbsent Records `json:"recordsabsent,omitempty"` // ENSURE_ABSENT
	KeepUnknown  bool    `json:"keepunknown,omitempty"`   // NO_PURGE

	Unmanaged       []*UnmanagedConfig `json:"unmanaged,omitempty"`                      // IGNORE()
	UnmanagedUnsafe bool               `json:"unmanaged_disable_safety_check,omitempty"` // DISABLE_IGNORE_SAFETY_CHECK

	IgnoreExternalDNS bool   `json:"ignore_external_dns,omitempty"` // IGNORE_EXTERNAL_DNS
	ExternalDNSPrefix string `json:"external_dns_prefix,omitempty"` // IGNORE_EXTERNAL_DNS prefix

	AutoDNSSEC string `json:"auto_dnssec,omitempty"` // "", "on", "off"

	// These fields contain instantiated provider instances once everything is linked up.
	// This linking is in two phases:
	// 1. Metadata (name/type) is available just from the dnsconfig. Validation can use that.
	// 2. Final driver instances are loaded after we load credentials. Any actual provider interaction requires that.
	RegistrarInstance    *RegistrarInstance     `json:"-"`
	DNSProviderInstances []*DNSProviderInstance `json:"-"`

	// Raw user-input from dnsconfig.js that will be processed into RecordConfigs later:
	RawRecords []RawRecordConfig `json:"rawrecords,omitempty"`
	// contains filtered or unexported fields
}

DomainConfig describes a DNS domain (technically a DNS zone).

func (*DomainConfig) Copy

func (dc *DomainConfig) Copy() (*DomainConfig, error)

Copy returns a deep copy of the DomainConfig.

func (*DomainConfig) DomainNameVarieties added in v4.28.0

func (dc *DomainConfig) DomainNameVarieties() *domaintags.DomainNameVarieties

DomainNameVarieties returns the domain's names in various forms.

func (*DomainConfig) Filter

func (dc *DomainConfig) Filter(f func(r *RecordConfig) bool)

Filter removes all records that don't match the filter f.

func (*DomainConfig) GetChangeCount added in v4.14.0

func (dc *DomainConfig) GetChangeCount(providerName string) int

GetChangeCount accumulates change count in a thread-safe way.

func (*DomainConfig) GetCorrections added in v4.9.0

func (dc *DomainConfig) GetCorrections(providerName string) []*Correction

GetCorrections returns the accumulated corrections for providerName.

func (*DomainConfig) GetPopulateCorrections added in v4.15.4

func (dc *DomainConfig) GetPopulateCorrections(providerName string) []*Correction

GetPopulateCorrections returns zone corrections in a thread-safe way.

func (*DomainConfig) GetSplitHorizonNames

func (dc *DomainConfig) GetSplitHorizonNames() (name, uniquename, tag string)

GetSplitHorizonNames returns the domain's name, uniquename, and tag. Deprecated: use .Name, .Uniquename, and .Tag directly instead.

func (*DomainConfig) GetUniqueName

func (dc *DomainConfig) GetUniqueName() (uniquename string)

GetUniqueName returns the domain's uniquename. Deprecated: dc.UniqueName directly instead.

func (*DomainConfig) IncrementChangeCount added in v4.14.0

func (dc *DomainConfig) IncrementChangeCount(providerName string, delta int)

IncrementChangeCount accumulates change count in a thread-safe way.

func (*DomainConfig) PostProcess added in v4.28.0

func (dc *DomainConfig) PostProcess()

PostProcess performs and post-processing required after running dnsconfig.js and loading the result. It is called by dns.go's PostProcess() function.

func (*DomainConfig) Punycode

func (dc *DomainConfig) Punycode() error

Punycode will convert all records to punycode format. It will encode: - Name - NameFQDN - Target (CNAME and MX only)

func (*DomainConfig) StoreCorrections added in v4.9.0

func (dc *DomainConfig) StoreCorrections(providerName string, corrections []*Correction)

StoreCorrections accumulates corrections in a thread-safe way.

func (*DomainConfig) StorePopulateCorrections added in v4.15.4

func (dc *DomainConfig) StorePopulateCorrections(providerName string, corrections []*Correction)

StorePopulateCorrections accumulates corrections in a thread-safe way.

type Nameserver

type Nameserver struct {
	Name string `json:"name"` // Normalized to a FQDN with NO trailing "."

}

Nameserver describes a nameserver.

func ToNameservers

func ToNameservers(nss []string) ([]*Nameserver, error)

ToNameservers turns a list of strings into a list of Nameservers. It is an error if any string has a trailing dot. Either remove the trailing dot before you call this or (much preferred) use ToNameserversStripTD.

func ToNameserversStripTD

func ToNameserversStripTD(nss []string) ([]*Nameserver, error)

ToNameserversStripTD is like ToNameservers but strips the trailing dot from each item. It is an error if there is no trailing dot.

func (*Nameserver) String

func (n *Nameserver) String() string

type ProviderBase

type ProviderBase struct {
	Name         string
	IsDefault    bool
	ProviderType string
}

ProviderBase describes providers.

type RawRecordConfig added in v4.12.3

type RawRecordConfig struct {
	Type    string           `json:"type"`
	Args    []any            `json:"args,omitempty"`
	Metas   []map[string]any `json:"metas,omitempty"`
	TTL     uint32           `json:"ttl,omitempty"`
	FilePos string           `json:"filepos"` // Where in the file this record was defined.
}

RawRecordConfig stores the user-input from dnsconfig.js for a DNS Record. This is later processed (in Go) to become a RecordConfig. NOTE: Only newer rtypes are processed this way. Eventually the legacy types will be converted.

type RecordConfig

type RecordConfig struct {
	// Type is the DNS record type (rtype), all caps, "A", "MX", etc.
	Type string `json:"type"`

	// TTL is the DNS record's TTL in seconds. 0 means provider default.
	TTL uint32 `json:"ttl,omitempty"`

	// Name is the shortname i.e. the FQDN without the parent domains's suffix.
	// It should never be "".  Record at the apex (naked domain) are represented by "@".
	NameRaw     string `json:"name_raw,omitempty"`     // .Name as the user entered it in dnsconfig.js
	Name        string `json:"name"`                   // The short name, PunyCode. See above.
	NameUnicode string `json:"name_unicode,omitempty"` // .Name as Unicode (downcased, then convertedot Unicode).

	// This is the FQDN version of .Name. It should never have a trailing ".".
	NameFQDNRaw     string `json:"-"` // .NameFQDN as the user entered it in dnsconfig.js (downcased).
	NameFQDN        string `json:"-"` // Must end with ".$origin".
	NameFQDNUnicode string `json:"-"` // .NameFQDN as Unicode (downcased, then convertedot Unicode).

	// F is the binary representation of the record's data usually a dns.XYZ struct.
	// Always stored in Punycode, not Unicode. Downcased where applicable.
	F any `json:"fields,omitempty"`

	// Comparable is an opaque string that can be used to compare two
	// RecordConfigs for equality. Typically this is the Zonefile line minus the
	// label and TTL.
	Comparable string `json:"comparable,omitempty"` // Cache of ToComparableNoTTL()

	// ZonefilePartial is the partial zonefile line for this record, excluding
	// the label and TTL.  If this is not an official RR type, we invent the format.
	ZonefilePartial string `json:"zonfefilepartial,omitempty"`

	// Metadata (desired) added to the record via dnsconfig.js. For example: A("foo", "1.2.3.4", {metakey: "value"})
	Metadata map[string]string `json:"meta,omitempty"`

	// FilePos (desired) is "filename:line:char" of the record in dnsconfig.js (desired).
	FilePos string `json:"filepos"`

	// Subdomain (if non-empty) contains the subdomain path for this record.
	// When .Name* fields are updated to include the subdomain, this field is
	// cleared.
	SubDomain string `json:"subdomain,omitempty"`

	// Original is a pointer to the provider-specific record object. When
	// getting the records via the API, we store the original object here.
	// Later if we need to pull out an ID or other provider-specific field, we
	// can.  Typically deleting or updating a record requires knowing its ID.
	Original any `json:"-"`

	MxPreference       uint16            `json:"mxpreference,omitempty"`
	SrvPriority        uint16            `json:"srvpriority,omitempty"`
	SrvWeight          uint16            `json:"srvweight,omitempty"`
	SrvPort            uint16            `json:"srvport,omitempty"`
	CaaTag             string            `json:"caatag,omitempty"`
	CaaFlag            uint8             `json:"caaflag,omitempty"`
	DsKeyTag           uint16            `json:"dskeytag,omitempty"`
	DsAlgorithm        uint8             `json:"dsalgorithm,omitempty"`
	DsDigestType       uint8             `json:"dsdigesttype,omitempty"`
	DsDigest           string            `json:"dsdigest,omitempty"`
	DnskeyFlags        uint16            `json:"dnskeyflags,omitempty"`
	DnskeyProtocol     uint8             `json:"dnskeyprotocol,omitempty"`
	DnskeyAlgorithm    uint8             `json:"dnskeyalgorithm,omitempty"`
	DnskeyPublicKey    string            `json:"dnskeypublickey,omitempty"`
	LocVersion         uint8             `json:"locversion,omitempty"`
	LocSize            uint8             `json:"locsize,omitempty"`
	LocHorizPre        uint8             `json:"lochorizpre,omitempty"`
	LocVertPre         uint8             `json:"locvertpre,omitempty"`
	LocLatitude        uint32            `json:"loclatitude,omitempty"`
	LocLongitude       uint32            `json:"loclongitude,omitempty"`
	LocAltitude        uint32            `json:"localtitude,omitempty"`
	LuaRType           string            `json:"luartype,omitempty"`
	NaptrOrder         uint16            `json:"naptrorder,omitempty"`
	NaptrPreference    uint16            `json:"naptrpreference,omitempty"`
	NaptrFlags         string            `json:"naptrflags,omitempty"`
	NaptrService       string            `json:"naptrservice,omitempty"`
	NaptrRegexp        string            `json:"naptrregexp,omitempty"`
	SmimeaUsage        uint8             `json:"smimeausage,omitempty"`
	SmimeaSelector     uint8             `json:"smimeaselector,omitempty"`
	SmimeaMatchingType uint8             `json:"smimeamatchingtype,omitempty"`
	SshfpAlgorithm     uint8             `json:"sshfpalgorithm,omitempty"`
	SshfpFingerprint   uint8             `json:"sshfpfingerprint,omitempty"`
	SoaMbox            string            `json:"soambox,omitempty"`
	SoaSerial          uint32            `json:"soaserial,omitempty"`
	SoaRefresh         uint32            `json:"soarefresh,omitempty"`
	SoaRetry           uint32            `json:"soaretry,omitempty"`
	SoaExpire          uint32            `json:"soaexpire,omitempty"`
	SoaMinttl          uint32            `json:"soaminttl,omitempty"`
	SvcPriority        uint16            `json:"svcpriority,omitempty"`
	SvcParams          string            `json:"svcparams,omitempty"`
	TlsaUsage          uint8             `json:"tlsausage,omitempty"`
	TlsaSelector       uint8             `json:"tlsaselector,omitempty"`
	TlsaMatchingType   uint8             `json:"tlsamatchingtype,omitempty"`
	R53Alias           map[string]string `json:"r53_alias,omitempty"`
	AzureAlias         map[string]string `json:"azure_alias,omitempty"`
	AnswerType         string            `json:"answer_type,omitempty"`
	UnknownTypeName    string            `json:"unknown_type_name,omitempty"`
	// contains filtered or unexported fields
}

RecordConfig stores a DNS record whether it was created from data downloaded from a provider's API ("actual") or from user input in dndsconfig.js ("desired").

func RRtoRC

func RRtoRC(rr dns.RR, origin string) (RecordConfig, error)

RRtoRC converts dns.RR to RecordConfig

func RRtoRCTxtBug added in v4.7.0

func RRtoRCTxtBug(rr dns.RR, origin string) (RecordConfig, error)

RRtoRCTxtBug converts dns.RR to RecordConfig. Compensates for the backslash bug in github.com/miekg/dns/issues/1384.

func (*RecordConfig) ChangeType added in v4.17.0

func (rc *RecordConfig) ChangeType(newType string, _ string)

ChangeType converts rc to an rc of type newType. This is only needed when converting from one type to another. Do not use this when initializing a new record.

Typically this is used to convert an ALIAS to a CNAME, or SPF to TXT. Using this function future-proofs the code since eventually such changes will require extra steps.

func (*RecordConfig) Copy

func (rc *RecordConfig) Copy() (*RecordConfig, error)

Copy returns a deep copy of a RecordConfig.

func (*RecordConfig) GetDependencies added in v4.3.0

func (rc *RecordConfig) GetDependencies() []string

GetDependencies returns the FQDNs on which this record dependents

func (*RecordConfig) GetLabel

func (rc *RecordConfig) GetLabel() string

GetLabel returns the shortname of the label associated with this RecordConfig. It will never end with ".". It does not need further shortening (i.e. if it returns "foo.com" and the domain is "foo.com" then the FQDN is actually "foo.com.foo.com"). It will never be "" (the apex is returned as "@").

func (*RecordConfig) GetLabelFQDN

func (rc *RecordConfig) GetLabelFQDN() string

GetLabelFQDN returns the FQDN of the label associated with this RecordConfig. It will not end with ".".

func (*RecordConfig) GetSVCBValue added in v4.10.0

func (rc *RecordConfig) GetSVCBValue() []dns.SVCBKeyValue

GetSVCBValue returns the SVCB Key/Values as a list of Key/Values.

func (*RecordConfig) GetTargetCombined

func (rc *RecordConfig) GetTargetCombined() string

GetTargetCombined returns a string with the various fields combined. For example, an MX record might output `10 mx10.example.tld`. WARNING: How TXT records are handled is buggy but we can't change it because code depends on the bugs. Use Get GetTargetCombinedFunc() instead.

func (*RecordConfig) GetTargetCombinedFunc added in v4.7.0

func (rc *RecordConfig) GetTargetCombinedFunc(encodeFn func(s string) string) string

GetTargetCombinedFunc returns all the rdata fields of a RecordConfig as one string. How TXT records are encoded is defined by encodeFn. If encodeFn is nil the TXT data is returned unaltered.

func (*RecordConfig) GetTargetDebug

func (rc *RecordConfig) GetTargetDebug() string

GetTargetDebug returns a string with the various fields spelled out.

func (*RecordConfig) GetTargetField

func (rc *RecordConfig) GetTargetField() string

GetTargetField returns the target. There may be other fields, but they are not included. For example, the .MxPreference field of an MX record isn't included.

func (*RecordConfig) GetTargetIP

func (rc *RecordConfig) GetTargetIP() net.IP

GetTargetIP returns the net.IP stored in .target.

func (*RecordConfig) GetTargetRFC1035Quoted

func (rc *RecordConfig) GetTargetRFC1035Quoted() string

GetTargetRFC1035Quoted returns the target as it would be in an RFC1035-style zonefile. Do not use this function if RecordConfig might be a pseudo-rtype such as R53_ALIAS. Use GetTargetCombined() instead.

func (*RecordConfig) GetTargetTXTJoined

func (rc *RecordConfig) GetTargetTXTJoined() string

GetTargetTXTJoined returns the TXT target as one string.

func (*RecordConfig) GetTargetTXTSegmentCount added in v4.6.1

func (rc *RecordConfig) GetTargetTXTSegmentCount() int

GetTargetTXTSegmentCount returns the number of 255-octet segments required to store TXT target.

func (*RecordConfig) GetTargetTXTSegmented added in v4.6.1

func (rc *RecordConfig) GetTargetTXTSegmented() []string

GetTargetTXTSegmented returns the TXT target as 255-octet segments, with the remainder in the last segment.

func (*RecordConfig) HasFormatIdenticalToTXT

func (rc *RecordConfig) HasFormatIdenticalToTXT() bool

HasFormatIdenticalToTXT returns if a RecordConfig has a format which is identical to TXT, such as SPF. For more details, read https://tools.ietf.org/html/rfc4408#section-3.1.1

func (*RecordConfig) IsModernType added in v4.28.0

func (rc *RecordConfig) IsModernType() bool

IsModernType returns true if this RecordConfig is a record type implemented in the new ("Modern") style (i.e. uses the RecordConfig .F field to store the rdata of the record).

Since this relies on .F, it must be used only after the RecordConfig has been populated. Otherwise, use rtypecontrol.IsModernType(recordTypeName), which takes the type name as input.

NOTE: Do not confuse this with rtypeinfo.IsModernType() which provides similar functionality. This function is used to have a RecordConfig reveal if it uses a modern type. rtypeinfo.IsModernType() takes the rtype name as a string argument.

FUTURE(tlim): Once all record types have been migrated to use ".F", this function can be removed.

func (*RecordConfig) Key

func (rc *RecordConfig) Key() RecordKey

Key converts a RecordConfig into a RecordKey.

func (*RecordConfig) MarshalJSON

func (rc *RecordConfig) MarshalJSON() ([]byte, error)

MarshalJSON marshals RecordConfig.

func (*RecordConfig) MustSetTarget added in v4.15.4

func (rc *RecordConfig) MustSetTarget(target string)

MustSetTarget is like SetTarget, but panics if an error occurs. It should only be used in _test.go files and in the init() function.

func (*RecordConfig) PopulateFromString

func (rc *RecordConfig) PopulateFromString(rtype, contents, origin string) error

PopulateFromString populates a RecordConfig given a type and string. Many providers give all the parameters of a resource record in one big string. This helper function lets you not re-invent the wheel.

NOTE: You almost always want to special-case TXT records. Every provider seems to quote them differently.

Recommended calling convention: Process the exceptions first, then use the PopulateFromString function for everything else.

 rtype := FILL_IN_TYPE
	var err error
 rc := &models.RecordConfig{Type: rtype}
 rc.SetLabelFromFQDN(FILL_IN_NAME, origin)
 rc.TTL = uint32(FILL_IN_TTL)
 rc.Original = FILL_IN_ORIGINAL // The raw data received from provider (if needed later)
	switch rtype {
	case "MX":
		// MX priority in a separate field.
		err = rc.SetTargetMX(cr.Priority, target)
	case "TXT":
		// TXT records are stored verbatim; no quoting/escaping to parse.
		err = rc.SetTargetTXT(target)
	default:
		err = rc.PopulateFromString(rtype, target, origin)
	}
	if err != nil {
		return nil, fmt.Errorf("unparsable record type=%q received from PROVDER_NAME: %w", rtype, err)
	}
	return rc, nil

func (*RecordConfig) PopulateFromStringFunc added in v4.7.0

func (rc *RecordConfig) PopulateFromStringFunc(rtype, contents, origin string, txtFn func(s string) (string, error)) error

PopulateFromStringFunc populates a RecordConfig by parsing a common RFC1035-like format.

rtype: the resource record type (rtype)
contents: a string that contains all parameters of the record's rdata (see below)
txtFn: If rtype == "TXT", this function is used to parse contents, or nil if no parsing is needed.

The "contents" field is the format used in RFC1035 zonefiles. It is the text after the rtype. For example, in the line: foo IN MX 10 mx.example.com. contents stores everything after the "MX" (not including the space).

Typical values for txtFn include:

nil:  no parsing required.
txtutil.ParseQuoted: Parse via Tom's interpretation of RFC1035.
txtutil.ParseCombined: Backwards compatible with Parse via miekg's interpretation of RFC1035.

Many providers deliver record data in this format or something close to it. This function is provided to reduce the amount of duplicate code across providers. If a particular rtype is not handled as a particular provider expects, simply handle it beforehand as a special case.

Example 1: Normal use.

rtype := FILL_IN_RTYPE
rc := &models.RecordConfig{Type: rtype, TTL: FILL_IN_TTL}
rc.SetLabelFromFQDN(FILL_IN_NAME, origin)
rc.Original = FILL_IN_ORIGINAL // The raw data received from provider (if needed later)
if err = rc.PopulateFromStringFunc(rtype, target, origin, nil); err != nil {
	return nil, fmt.Errorf("unparsable record type=%q received from PROVDER_NAME: %w", rtype, err)
}
return rc, nil

Example 2: Use your own MX parser.

rtype := FILL_IN_RTYPE
rc := &models.RecordConfig{Type: rtype, TTL: FILL_IN_TTL}
rc.SetLabelFromFQDN(FILL_IN_NAME, origin)
rc.Original = FILL_IN_ORIGINAL // The raw data received from provider (if needed later)
switch rtype {
case "MX":
	// MX priority in a separate field.
	err = rc.SetTargetMX(cr.Priority, target)
default:
	err = rc.PopulateFromString(rtype, target, origin)
}
if err != nil {
	return nil, fmt.Errorf("unparsable record type=%q received from PROVDER_NAME: %w", rtype, err)
}
return rc, nil

func (*RecordConfig) SetLOCParams

func (rc *RecordConfig) SetLOCParams(d1 uint8, m1 uint8, s1 float32, ns string,
	d2 uint8, m2 uint8, s2 float32, ew string, al float32, sz float32, hp float32, vp float32,
) error

SetLOCParams is an intermediate function which passes the 12 input parameters for further processing to the LOC native 7 input binary format: LocVersion (0), LocLatitude, LocLongitude, LocAltitude, LocSize, LocVertPre, LocHorizPre

func (*RecordConfig) SetLabel

func (rc *RecordConfig) SetLabel(short, origin string)

SetLabel sets the .Name/.NameFQDN fields given a short name and origin. origin must not have a trailing dot: The entire code base maintains dc.Name without the trailig dot. Finding a dot here means something is very wrong.

short must not have a training dot: That would mean you have a FQDN, and shouldn't be using SetLabel(). Maybe SetLabelFromFQDN()?

func (*RecordConfig) SetLabelFromFQDN

func (rc *RecordConfig) SetLabelFromFQDN(fqdn, origin string)

SetLabelFromFQDN sets the .Name/.NameFQDN fields given a FQDN and origin. fqdn may have a trailing "." but it is not required. origin may not have a trailing dot.

func (*RecordConfig) SetTarget

func (rc *RecordConfig) SetTarget(target string) error

SetTarget sets the target, assuming that the rtype is appropriate.

func (*RecordConfig) SetTargetCAA

func (rc *RecordConfig) SetTargetCAA(flag uint8, tag string, target string) error

SetTargetCAA sets the CAA fields.

func (*RecordConfig) SetTargetCAAString

func (rc *RecordConfig) SetTargetCAAString(s string) error

SetTargetCAAString is like SetTargetCAA but accepts one big string. Ex: `0 issue "letsencrypt.org"`

func (*RecordConfig) SetTargetCAAStrings

func (rc *RecordConfig) SetTargetCAAStrings(flag, tag, target string) error

SetTargetCAAStrings is like SetTargetCAA but accepts strings.

func (*RecordConfig) SetTargetDNSKEY added in v4.10.0

func (rc *RecordConfig) SetTargetDNSKEY(flags uint16, protocol, algorithm uint8, publicKey string) error

SetTargetDNSKEY sets the DNSKEY fields.

func (*RecordConfig) SetTargetDNSKEYString added in v4.10.0

func (rc *RecordConfig) SetTargetDNSKEYString(s string) error

SetTargetDNSKEYString is like SetTargetDNSKEY but accepts one big string.

func (*RecordConfig) SetTargetDNSKEYStrings added in v4.10.0

func (rc *RecordConfig) SetTargetDNSKEYStrings(flags, protocol, algorithm, publicKey string) error

SetTargetDNSKEYStrings is like SetTargetDNSKEY but accepts strings.

func (*RecordConfig) SetTargetDS

func (rc *RecordConfig) SetTargetDS(keytag uint16, algorithm, digesttype uint8, digest string) error

SetTargetDS sets the DS fields.

func (*RecordConfig) SetTargetDSString

func (rc *RecordConfig) SetTargetDSString(s string) error

SetTargetDSString is like SetTargetDS but accepts one big string.

func (*RecordConfig) SetTargetDSStrings

func (rc *RecordConfig) SetTargetDSStrings(keytag, algorithm, digesttype, digest string) error

SetTargetDSStrings is like SetTargetDS but accepts strings.

func (*RecordConfig) SetTargetIP

func (rc *RecordConfig) SetTargetIP(ip net.IP) error

SetTargetIP sets the target to an IP, verifying this is an appropriate rtype.

func (*RecordConfig) SetTargetLOC

func (rc *RecordConfig) SetTargetLOC(ver uint8, lat uint32, lon uint32, alt uint32, siz uint8, hzp uint8, vtp uint8) error

SetTargetLOC sets the LOC fields from the rr.LOC type properties.

func (*RecordConfig) SetTargetLOCString

func (rc *RecordConfig) SetTargetLOCString(origin string, contents string) error

SetTargetLOCString is like SetTargetLOC but accepts one big string and origin Normally this is used when we receive a record string from provider records because e.g. the provider API passed rc.PopulateFromString()

func (*RecordConfig) SetTargetMX

func (rc *RecordConfig) SetTargetMX(pref uint16, target string) error

SetTargetMX sets the MX fields.

func (*RecordConfig) SetTargetMXString

func (rc *RecordConfig) SetTargetMXString(s string) error

SetTargetMXString is like SetTargetMX but accepts one big string.

func (*RecordConfig) SetTargetMXStrings

func (rc *RecordConfig) SetTargetMXStrings(pref, target string) error

SetTargetMXStrings is like SetTargetMX but accepts strings.

func (*RecordConfig) SetTargetNAPTR

func (rc *RecordConfig) SetTargetNAPTR(order uint16, preference uint16, flags string, service string, regexp string, target string) error

SetTargetNAPTR sets the NAPTR fields.

func (*RecordConfig) SetTargetNAPTRString

func (rc *RecordConfig) SetTargetNAPTRString(s string) error

SetTargetNAPTRString is like SetTargetNAPTR but accepts one big string.

func (*RecordConfig) SetTargetNAPTRStrings

func (rc *RecordConfig) SetTargetNAPTRStrings(order, preference, flags string, service string, regexp string, target string) error

SetTargetNAPTRStrings is like SetTargetNAPTR but accepts strings.

func (*RecordConfig) SetTargetSMIMEA added in v4.26.0

func (rc *RecordConfig) SetTargetSMIMEA(usage, selector, matchingtype uint8, target string) error

SetTargetSMIMEA sets the SMIMEA fields.

func (*RecordConfig) SetTargetSMIMEAString added in v4.26.0

func (rc *RecordConfig) SetTargetSMIMEAString(s string) error

SetTargetSMIMEAString is like SetTargetSMIMEA but accepts one big string.

func (*RecordConfig) SetTargetSMIMEAStrings added in v4.26.0

func (rc *RecordConfig) SetTargetSMIMEAStrings(usage, selector, matchingtype, target string) (err error)

SetTargetSMIMEAStrings is like SetTargetSMIMEA but accepts strings.

func (*RecordConfig) SetTargetSOA

func (rc *RecordConfig) SetTargetSOA(ns, mbox string, serial, refresh, retry, expire, minttl uint32) error

SetTargetSOA sets the SOA fields.

func (*RecordConfig) SetTargetSOAString

func (rc *RecordConfig) SetTargetSOAString(s string) error

SetTargetSOAString is like SetTargetSOA but accepts one big string.

func (*RecordConfig) SetTargetSOAStrings

func (rc *RecordConfig) SetTargetSOAStrings(ns, mbox, serial, refresh, retry, expire, minttl string) error

SetTargetSOAStrings is like SetTargetSOA but accepts strings.

func (*RecordConfig) SetTargetSRV

func (rc *RecordConfig) SetTargetSRV(priority, weight, port uint16, target string) error

SetTargetSRV sets the SRV fields.

func (*RecordConfig) SetTargetSRVPriorityString

func (rc *RecordConfig) SetTargetSRVPriorityString(priority uint16, s string) error

SetTargetSRVPriorityString is like SetTargetSRV but accepts priority as an uint16 and the rest of the values joined in a string that needs to be parsed. This is a helper function that comes in handy when a provider re-uses the MX preference field as the SRV priority.

func (*RecordConfig) SetTargetSRVString

func (rc *RecordConfig) SetTargetSRVString(s string) error

SetTargetSRVString is like SetTargetSRV but accepts one big string to be parsed.

func (*RecordConfig) SetTargetSRVStrings

func (rc *RecordConfig) SetTargetSRVStrings(priority, weight, port, target string) (err error)

SetTargetSRVStrings is like SetTargetSRV but accepts all parameters as strings.

func (*RecordConfig) SetTargetSSHFP

func (rc *RecordConfig) SetTargetSSHFP(algorithm uint8, fingerprint uint8, target string) error

SetTargetSSHFP sets the SSHFP fields.

func (*RecordConfig) SetTargetSSHFPString

func (rc *RecordConfig) SetTargetSSHFPString(s string) error

SetTargetSSHFPString is like SetTargetSSHFP but accepts one big string.

func (*RecordConfig) SetTargetSSHFPStrings

func (rc *RecordConfig) SetTargetSSHFPStrings(algorithm, fingerprint, target string) error

SetTargetSSHFPStrings is like SetTargetSSHFP but accepts strings.

func (*RecordConfig) SetTargetSVCB added in v4.10.0

func (rc *RecordConfig) SetTargetSVCB(priority uint16, target string, params []dns.SVCBKeyValue) error

SetTargetSVCB sets the SVCB fields.

func (*RecordConfig) SetTargetSVCBString added in v4.10.0

func (rc *RecordConfig) SetTargetSVCBString(origin, contents string) error

SetTargetSVCBString is like SetTargetSVCB but accepts one big string and the origin so parsing can be done using miekg/dns.

func (*RecordConfig) SetTargetTLSA

func (rc *RecordConfig) SetTargetTLSA(usage, selector, matchingtype uint8, target string) error

SetTargetTLSA sets the TLSA fields.

func (*RecordConfig) SetTargetTLSAString

func (rc *RecordConfig) SetTargetTLSAString(s string) error

SetTargetTLSAString is like SetTargetTLSA but accepts one big string.

func (*RecordConfig) SetTargetTLSAStrings

func (rc *RecordConfig) SetTargetTLSAStrings(usage, selector, matchingtype, target string) (err error)

SetTargetTLSAStrings is like SetTargetTLSA but accepts strings.

func (*RecordConfig) SetTargetTXT

func (rc *RecordConfig) SetTargetTXT(s string) error

SetTargetTXT sets the TXT fields when there is 1 string.

func (*RecordConfig) SetTargetTXTs

func (rc *RecordConfig) SetTargetTXTs(s []string) error

SetTargetTXTs sets the TXT fields when there are many strings. They are stored concatenated.

func (*RecordConfig) String

func (rc *RecordConfig) String() string

String returns the text representation of the resource record.

func (*RecordConfig) ToComparableNoTTL

func (rc *RecordConfig) ToComparableNoTTL() string

ToComparableNoTTL returns a comparison string. If you need to compare two RecordConfigs, you can simply compare the string returned by this function. The comparison includes all fields except TTL and any provider-specific metafields. Provider-specific metafields like CF_PROXY are not the same as pseudo-records like ANAME or R53_ALIAS

func (*RecordConfig) ToRR

func (rc *RecordConfig) ToRR() dns.RR

ToRR converts a RecordConfig to a dns.RR.

func (*RecordConfig) UnmarshalJSON

func (rc *RecordConfig) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals RecordConfig.

type RecordDB

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

RecordDB is a container of many RecordConfig, queryable by various methods. The first to be implemented is as a hash with label:type as the index.

func NewRecordDBFromRecords

func NewRecordDBFromRecords(recs Records, zone string) *RecordDB

NewRecordDBFromRecords creates a RecordDB from a list of RecordConfig.

func (*RecordDB) ContainsLT

func (recdb *RecordDB) ContainsLT(rec *RecordConfig) bool

ContainsLT returns true if recdb contains rec. Matching is done on the record's label and type (i.e. the RecordKey)

type RecordKey

type RecordKey struct {
	NameFQDN string
	Type     string
}

RecordKey represents a resource record in a format used by some systems.

func (*RecordKey) String

func (rk *RecordKey) String() string

type Records

type Records []*RecordConfig

Records is a list of *RecordConfig.

func (Records) GetAllDependencies added in v4.3.0

func (recs Records) GetAllDependencies() []string

GetAllDependencies concatinates all dependencies of all records

func (Records) GetByType

func (recs Records) GetByType(typeName string) Records

GetByType returns the records that match rtype typeName.

func (Records) GroupedByFQDN

func (recs Records) GroupedByFQDN() ([]string, map[string]Records)

GroupedByFQDN returns a map of keys to records, grouped by FQDN.

func (Records) GroupedByKey

func (recs Records) GroupedByKey() map[RecordKey]Records

GroupedByKey returns a map of keys to records.

func (Records) HasRecordTypeName

func (recs Records) HasRecordTypeName(rtype, name string) bool

HasRecordTypeName returns True if there is a record with this rtype and name.

type Registrar

type Registrar interface {
	GetRegistrarCorrections(dc *DomainConfig) ([]*Correction, error)
}

Registrar is an interface for Registrar plug-ins.

type RegistrarConfig

type RegistrarConfig struct {
	Name     string          `json:"name"`
	Type     string          `json:"type"`
	Metadata json.RawMessage `json:"meta,omitempty"`
}

RegistrarConfig describes a registrar.

type RegistrarInstance

type RegistrarInstance struct {
	ProviderBase
	Driver Registrar
}

RegistrarInstance is a single registrar.

type UnmanagedConfig

type UnmanagedConfig struct {
	// Glob pattern for matching labels.
	LabelPattern string    `json:"label_pattern,omitempty"`
	LabelGlob    glob.Glob `json:"-"` // Compiled version

	// Comma-separated list of DNS Resource Types.
	RTypePattern string              `json:"rType_pattern,omitempty"`
	RTypeMap     map[string]struct{} `json:"-"` // map of RTypes or len()=0 for all

	// Glob pattern for matching targets.
	TargetPattern string    `json:"target_pattern,omitempty"`
	TargetGlob    glob.Glob `json:"-"` // Compiled version
}

UnmanagedConfig describes an IGNORE() rule. NB(tlim): This is called "Unmanaged" because the original design was to call this function UNMANAGED(). However we then realized that we could repurpose IGNORE() without any compatibility issues. NB(tlim): TechDebt: UnmanagedConfig and DebugUnmanagedConfig should be moved to pkg/diff2/handsoff.go and the following fields could be unexported: LabelGlob, RTypeMap, and TargetGlob

Jump to

Keyboard shortcuts

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