providers

package
v5.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RecordTypeCapabilities = map[string]Capability{
	"AKAMAICDN": CanUseAKAMAICDN, "AKAMAITLC": CanUseAKAMAITLC,
	"ALIAS": CanUseAlias, "AZURE_ALIAS": CanUseAzureAlias,
	"CAA": CanUseCAA, "DHCID": CanUseDHCID, "DNAME": CanUseDNAME,
	"DNSKEY": CanUseDNSKEY, "DS": CanUseDS, "HTTPS": CanUseHTTPS,
	"LOC": CanUseLOC, "NAPTR": CanUseNAPTR, "OPENPGPKEY": CanUseOPENPGPKEY,
	"PTR": CanUsePTR, "R53_ALIAS": CanUseRoute53Alias, "RP": CanUseRP,
	"SMIMEA": CanUseSMIMEA, "SOA": CanUseSOA, "SRV": CanUseSRV,
	"SSHFP": CanUseSSHFP, "SVCB": CanUseSVCB, "TLSA": CanUseTLSA,
}

RecordTypeCapabilities bridges SupportedTypes and legacy feature consumers. Treat this map as read-only. Operational capabilities do not belong here.

Functions

func AuditRecords

func AuditRecords(dType string, rcs models.Records) []error

AuditRecords calls the RecordAudit function for a provider.

func CanonicalName added in v5.4.0

func CanonicalName(name string) string

CanonicalName resolves a provider-type alias. Unknown names are returned unchanged so callers can retain their existing validation and diagnostics.

func EndToNative

func EndToNative(observer ConversionObserver, function string, before ConversionSnapshot, records models.Records, result any, err error)

EndToNative safely completes an observation when observer may be nil.

func EndToRC

func EndToRC(observer ConversionObserver, function string, before ConversionSnapshot, native any, result models.Records, err error)

EndToRC safely completes an observation when observer may be nil.

func Finalize added in v5.4.0

func Finalize() error

Finalize validates selectors against the complete record catalog and derives compatibility capabilities. Call after package registration and before concurrent reads. The _all package does this at startup; accessors also ensure finalization for programs/tests importing individual providers.

Register and private-type registration invalidate the result. Tests adding either must finish registration before reading again. Repeated calls without registrations do not mutate definitions. Registration concurrent with reads remains unsupported.

func GetDefaultTTL

func GetDefaultTTL(providerName string) uint32

GetDefaultTTL returns the provider's default TTL, or 0 if not registered.

func ProviderHasCapability

func ProviderHasCapability(pType string, capa Capability) bool

ProviderHasCapability returns true if provider has capability.

func Register added in v5.4.0

func Register[T InitializableProvider](name string, definition Definition)

Register registers a concrete pointer-to-struct implementation. Invalid or conflicting declarations panic during startup, before any provider is used. Call it during package initialization, before concurrent registry reads. Registration inspects interfaces; it never calls Initialize. Supplied slices, maps, and notes must not be modified after registration.

Types

type Capability

type Capability int

Capability is a bitmasked set of "features" that a provider supports. Only use constants from this package.

const (

	// CanAutoDNSSEC indicates that the provider can automatically handle DNSSEC,
	// so folks can ask for that.
	CanAutoDNSSEC Capability = iota

	// CanConcur indicates the provider can be used concurrently to gather zone data.
	// Can() indicates that it has been tested and shown to work concurrently.
	// Cannot() indicates it has not been tested OR it has been shown to not
	// work when used concurrently.  The default is Cannot().
	CanConcur

	// CanGetZones indicates the provider can enumerate zones (get-zones ... all).
	// Reading explicitly named zones does not require this capability.
	CanGetZones

	// CanUseAKAMAICDN indicates the provider support the specific AKAMAICDN records that only the Akamai EdgeDns provider supports.
	CanUseAKAMAICDN

	// CanUseAlias indicates the provider support ALIAS records (or flattened CNAMES). Up to the provider to translate them to the appropriate record type.
	CanUseAlias

	// CanUseAzureAlias indicates the provider support the specific Azure_ALIAS records that only the Azure provider supports.
	CanUseAzureAlias

	// CanUseCAA indicates the provider can handle CAA records.
	CanUseCAA

	// CanUseDHCID indicates the provider can handle DHCID records.
	CanUseDHCID

	// CanUseDNAME indicates the provider can handle DNAME records.
	CanUseDNAME

	// CanUseDS indicates that the provider can handle DS record types. This
	// implies CanUseDSForChildren without specifying the latter explicitly.
	CanUseDS

	// CanUseDSForChildren indicates the provider can handle DS record types, but
	// only for children records, not at the root of the zone.
	CanUseDSForChildren

	// CanUseHTTPS indicates the provider can handle HTTPS records.
	CanUseHTTPS

	// CanUseLOC indicates whether service provider handles LOC records.
	CanUseLOC

	// CanUseNAPTR indicates the provider can handle NAPTR records.
	CanUseNAPTR

	// CanUsePTR indicates the provider can handle PTR records.
	CanUsePTR

	// CanUseRoute53Alias indicates the provider support the specific R53_ALIAS records that only the Route53 provider supports.
	CanUseRoute53Alias

	// CanUseRP indicates the provider can handle RP records.
	CanUseRP

	// CanUseSMIMEA indicates the provider can handle SMIMEA records.
	CanUseSMIMEA

	// CanUseSOA indicates the provider supports full management of a zone's SOA record.
	CanUseSOA

	// CanUseSRV indicates the provider can handle SRV records.
	CanUseSRV

	// CanUseSSHFP indicates the provider can handle SSHFP records.
	CanUseSSHFP

	// CanUseSVCB indicates the provider can handle SVCB records.
	CanUseSVCB

	// CanUseTLSA indicates the provider can handle TLSA records.
	CanUseTLSA

	// CanUseDNSKEY indicates that the provider can handle DNSKEY records.
	CanUseDNSKEY

	// CanUseOPENPGPKEY indicates that the provider can handle OPENPGPKEY records.
	CanUseOPENPGPKEY

	// DocCreateDomains means provider can add domains with the `dnscontrol create-domains` command.
	DocCreateDomains

	// DocDualHost means provider allows full management of apex NS records, so we can safely dual-host with another provider.
	DocDualHost

	// DocOfficiallySupported means it is actively used and maintained by stack exchange.
	DocOfficiallySupported

	// CanUseAKAMAITLC indicates the provider supports the specific AKAMAITLC records that only the Akamai EdgeDns provider supports.
	CanUseAKAMAITLC
)

func (Capability) String

func (i Capability) String() string

type ConversionObserver

type ConversionObserver interface {
	BeginToRC(function string, native any) ConversionSnapshot
	EndToRC(function string, before ConversionSnapshot, nativeAfter any, result models.Records, err error)
	BeginToNative(function string, records models.Records) ConversionSnapshot
	EndToNative(function string, before ConversionSnapshot, recordsAfter models.Records, result any, err error)
}

ConversionObserver observes the exact inputs and outputs of provider record conversions. Implementations may also verify that conversions did not mutate their inputs.

type ConversionSnapshot

type ConversionSnapshot any

ConversionSnapshot is an opaque snapshot returned before a conversion and passed back after it. Its concrete type belongs to the observer.

func BeginToNative

func BeginToNative(observer ConversionObserver, function string, records models.Records) ConversionSnapshot

BeginToNative safely begins an observation when observer may be nil.

func BeginToRC

func BeginToRC(observer ConversionObserver, function string, native any) ConversionSnapshot

BeginToRC safely begins an observation when observer may be nil.

type CreateOption

type CreateOption func(*CreateOptions)

CreateOption customizes provider construction.

func WithConversionObserver

func WithConversionObserver(observer ConversionObserver) CreateOption

WithConversionObserver supplies an observer for provider record conversions.

type CreateOptions

type CreateOptions struct {
	ConversionObserver ConversionObserver
	// RequestedRole is set by the typed factory after caller options are applied.
	// It is exactly KindDNS or KindRegistrar for runtime instances.
	RequestedRole ProviderKind
}

CreateOptions holds dependencies supplied while constructing a provider.

func (*CreateOptions) WithDefaults added in v5.4.0

func (options *CreateOptions) WithDefaults() CreateOptions

WithDefaults returns a copy with shared defaults applied. A nil receiver and zero-valued options are equivalent. The requested role remains unspecified unless set by a typed factory.

type CredsField

type CredsField struct {
	// Key is the exact name of the field as it should appear inside the
	// creds.json provider entry (for example "apitoken" or "KeyId").
	Key string
	// Label is the human readable text shown when prompting.
	Label string
	// Help is a short sentence explaining the field.
	Help string
	// Secret masks the input when prompting. Ignored when Multiline is
	// also set, since the external editor does not mask input.
	Secret bool
	// Multiline opens the user's $EDITOR so values like PEM blocks with
	// embedded newlines can be entered in full.
	Multiline bool
	// Required makes the init command reject an empty value.
	Required bool
	// Default suggests a value. Presented as the pre filled answer.
	Default string
	// EnvVar, when set, is used as the default if the environment variable is
	// present. It overrides Default.
	EnvVar string
	// Choices restricts input to one of the listed values.
	Choices []string
	// ConfirmValue asks a yes/no question and stores this value on yes.
	ConfirmValue string
	// Validator can reject an entered value with an explanatory error.
	Validator func(string) error
	// Internal marks the field as a UI selector whose answer drives
	// ShowIf logic on later fields. Internal answers are not written to
	// creds.json.
	//
	// Convention: prefix the Key with an underscore (for example
	// "_authMethod") so it is visually distinct from real creds.json
	// keys when reading metadata registrations.
	Internal bool
	// ShowIf restricts when this field is shown. Each entry maps an
	// earlier field's Key to the value that must be selected for this
	// field to appear. An empty map means always show.
	ShowIf map[string]string
}

CredsField describes a single key/value pair that belongs in the provider entry inside creds.json.

type DNSServiceProvider

type DNSServiceProvider interface {
	models.DNSProvider
}

DNSServiceProvider is able to generate a set of corrections that need to be made to correct records for a domain. Implement this only if the provider is a DNS Service Provider (can update records in a DNS zone).

func CreateDNSProvider

func CreateDNSProvider(providerTypeName string, config map[string]string, meta json.RawMessage, opts ...CreateOption) (DNSServiceProvider, error)

CreateDNSProvider initializes a dns provider instance from given credentials.

type Definition added in v5.4.0

type Definition struct {
	// FriendlyName is the brand name ("Google", not "GCLOUD")
	FriendlyName string

	// Aliases (optional) is an optional list of aliases. For example, if
	// we rename CLOUDFLAREAPI to CLOUDFLARE, we would make CLOUDFLAREAPI an alias to
	// support legacy configurations.
	Aliases []string

	// Maintainer is the github username of the maintainer.
	Maintainer string

	// DefaultTTL (optional) minimum TTL when `get-zone` writes .js files
	DefaultTTL uint32

	// CredFields is a description of the creds.json fields for this provider. Used by "init".
	CredFields []CredsField

	// DocsURL optionally overrides https://docs.dnscontrol.org/provider/<lowercase name>
	// for legacy documentation paths. An override matching the default is an error.
	// Register fills an empty value with the default URL.
	DocsURL string
	// VendorAPIDocURL optionally links to the vendor's API documentation.
	VendorAPIDocURL string
	// PortalURL points to where a user can obtain API credentials.
	PortalURL string
	// Notes is optional onboarding text shown before prompting for credentials.
	Notes string
	// PostWrite prepares local resources after the wizard writes creds.json.
	PostWrite func(map[string]string) error

	// Nil capability notes fall back to Features. Explicit notes take precedence.
	CanAutoDNSSEC          *DocumentationNote
	CanConcur              *DocumentationNote
	CanUseDSForChildren    *DocumentationNote
	DocDualHost            *DocumentationNote
	DocOfficiallySupported *DocumentationNote
	RecordIdentity         RecordIdentityFunc
	Features               DocumentationNotes

	// SupportedTypes is an exhaustive declaration of record support. Nil means
	// Basic8 (A, AAAA, CAA, CNAME, MX, NS, SRV, TXT), except that non-nil
	// Features retains legacy validation. A non-nil empty slice declares no
	// support beyond Features.
	// Internal commands such as IMPORT_TRANSFORM do not belong in this list.
	SupportedTypes []string

	// Calculated by Register and Finalize. Providers must leave these fields unset.
	TypeName           string
	ImplementationType reflect.Type
	Kind               ProviderKind
	Initializer        Initializer
	RecordAuditor      RecordAuditor
	CanGetZones        bool
	DocCreateDomains   bool
	DerivedFeatures    DocumentationNotes
	// contains filtered or unexported fields
}

Definition describes a provider implementation, never a configured account. providers.Register is the main entry point. It registers the provider, generates the derived fields, and cross-checks for errors. Definitions and their nested metadata are read-only to callers. Framework finalization completes derived type capabilities before concurrent reads.

func AllDefinitions added in v5.4.0

func AllDefinitions() []*Definition

AllDefinitions returns canonical definitions sorted by TypeName. The returned pointers and their nested metadata must be treated as read-only.

func GetDefinition added in v5.4.0

func GetDefinition(name string) (*Definition, bool)

GetDefinition returns the stored provider definition. Canonical names and aliases return the same pointer. The definition and its nested metadata must be treated as read-only.

func (*Definition) RecordTypeSupport added in v5.4.0

func (d *Definition) RecordTypeSupport(name string) DocumentationNote

RecordTypeSupport returns the effective status and compatible legacy notes. Unknown types are unsupported, including when '*' is declared. In legacy mode this describes only explicit capabilities, not an exhaustive inventory.

func (*Definition) UsesSupportedTypes added in v5.4.0

func (d *Definition) UsesSupportedTypes() bool

UsesSupportedTypes reports whether validation must check every record type. Legacy Features without SupportedTypes retains the old validation coverage.

type DocumentationNote

type DocumentationNote struct {
	HasFeature    bool
	Unimplemented bool
	Comment       string
	Link          string
}

DocumentationNote is a way for providers to give more detail about what features they support.

func Can

func Can(comments ...string) *DocumentationNote

Can is a small helper for concisely creating Documentation Notes comments are variadic for easy omission. First is comment, second is link, the rest are ignored.

func Cannot

func Cannot(comments ...string) *DocumentationNote

Cannot is a small helper for concisely creating Documentation Notes comments are variadic for easy omission. First is comment, second is link, the rest are ignored.

func Unimplemented

func Unimplemented(comments ...string) *DocumentationNote

Unimplemented is a small helper for concisely creating Documentation Notes comments are variadic for easy omission. First is comment, second is link, the rest are ignored.

type DocumentationNotes

type DocumentationNotes map[Capability]*DocumentationNote

DocumentationNotes is a full list of notes for a single provider.

type InitializableProvider added in v5.4.0

type InitializableProvider interface {
	Initialize(map[string]string, json.RawMessage, *CreateOptions) error
}

InitializableProvider initializes a fresh provider instance. Implementations must populate the receiver, not replace it with a shared instance.

type Initializer added in v5.4.0

type Initializer func(map[string]string, json.RawMessage, *CreateOptions) (any, error)

Initializer allocates and initializes a fresh instance, returning nil on error.

type None

type None struct{}

None is a basic provider type that does absolutely nothing. Can be useful as a placeholder for third parties or unimplemented providers.

func (None) GetRegistrarCorrections

func (n None) GetRegistrarCorrections(dc *models.DomainConfig) ([]*models.Correction, error)

GetRegistrarCorrections returns corrections to update registrars.

func (*None) Initialize added in v5.4.0

func (*None) Initialize(map[string]string, json.RawMessage, *CreateOptions) error

Initialize needs no credentials or setup for the placeholder registrar.

type ProviderKind

type ProviderKind uint8

ProviderKind is a bitmask describing the capabilities a provider offers from the perspective of the DNSControl configuration.

const (
	// KindDNS marks a provider that can host DNS records.
	KindDNS ProviderKind = 1 << iota
	// KindRegistrar marks a provider that can act as a domain registrar.
	KindRegistrar
)

func (ProviderKind) Has

func (kind ProviderKind) Has(other ProviderKind) bool

Has reports whether the given kind bit is set.

type RecordAuditor

type RecordAuditor func(models.Records) []error

RecordAuditor is a function that verifies that all the records are supportable by this provider. It returns a list of errors detailing records that this provider can not support.

type RecordIdentityFunc added in v5.2.0

type RecordIdentityFunc func(*models.RecordConfig) string

RecordIdentityFunc returns the identity text of a record: text that distinguishes two records which share a label, rType and RDATA but are stored by the provider as separate objects (DNSPod record lines, Route 53 routing policies). Validation uses it for duplicate detection, and validation runs before the provider has read the zone, so the function must depend only on the record it is given.

func GetRecordIdentity added in v5.2.0

func GetRecordIdentity(dType string) RecordIdentityFunc

GetRecordIdentity returns the provider's RecordIdentity function, or nil if the provider does not declare one.

type Registrar

type Registrar interface {
	models.Registrar
}

Registrar is an interface for a domain registrar. It can return a list of needed corrections to be applied in the future. Implement this only if the provider is a "registrar" (i.e. can update the NS records of the parent to a domain).

func CreateRegistrar

func CreateRegistrar(rType string, config map[string]string, opts ...CreateOption) (Registrar, error)

CreateRegistrar initializes a registrar instance from given credentials.

type ZoneCreator

type ZoneCreator interface {
	EnsureZoneExists(dc *models.DomainConfig) error
}

ZoneCreator should be implemented by providers that have the ability to create zones (used for automatically creating zones if they don't exist).

type ZoneLister

type ZoneLister interface {
	ListZones() ([]string, error)
}

ZoneLister should be implemented by providers that have the ability to list the zones they manage. This facilitates using the "get-zones" command for "all" zones.

Directories

Path Synopsis
Package all is simply a container to reference all known provider implementations for easy import into other packages
Package all is simply a container to reference all known provider implementations for easy import into other packages

Jump to

Keyboard shortcuts

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