dns

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package dns manages DNS zones at an external authoritative provider (PowerDNS or Cloudflare). The provider holds the records; the panel stores which zone belongs to whom.

Records use PowerDNS's canonical presentation format everywhere: names and host targets are fully qualified with a trailing dot, TXT contents are quoted. The Cloudflare driver converts at its boundary.

Index

Constants

This section is empty.

Variables

View Source
var ErrExists = errors.New("the DNS provider already has this zone")

ErrExists is returned when the provider already has the zone.

View Source
var ErrNotFound = errors.New("zone not found at the DNS provider")

ErrNotFound is returned for a zone the provider does not know.

View Source
var Types = []string{"A", "AAAA", "CNAME", "MX", "TXT", "SRV", "CAA", "NS"}

Types customers may edit. SOA and the apex NS are managed by the provider.

Functions

func Fqdn

func Fqdn(name string) string

Fqdn lowercases a name and adds the trailing dot.

func InZone

func InZone(name, zone string) bool

InZone reports whether name is the zone apex or below it.

func Normalize

func Normalize(zone string, set *RRSet) error

Normalize validates and canonicalises a record set for zone (both fully qualified). A relative name ("www", "@") is completed with the zone.

func QuoteTXT

func QuoteTXT(v string) string

QuoteTXT turns text into a quoted TXT content, split into 255-byte strings. Already quoted input is kept.

func UnquoteTXT

func UnquoteTXT(v string) string

UnquoteTXT reverses QuoteTXT (for providers that take plain text).

func ValidName

func ValidName(name string) bool

ValidName reports whether name (fully qualified) is a DNS name; "*" is only allowed as the first label.

func ValidZone

func ValidZone(zone string) bool

ValidZone is a registrable-looking zone name: at least two labels, no wildcard.

Types

type Cloudflare

type Cloudflare struct {
	Token     string
	AccountID string
	BaseURL   string // default https://api.cloudflare.com/client/v4 (tests override it)
	Client    *http.Client
}

Cloudflare manages zones through the Cloudflare API v4 with an API token (Zone:Edit and DNS:Edit permissions).

func (*Cloudflare) CreateZone

func (c *Cloudflare) CreateZone(ctx context.Context, zone string) (string, []string, error)

func (*Cloudflare) DeleteRRSet

func (c *Cloudflare) DeleteRRSet(ctx context.Context, _, id, name, typ string) error

func (*Cloudflare) DeleteZone

func (c *Cloudflare) DeleteZone(ctx context.Context, _, id string) error

func (*Cloudflare) RRSets

func (c *Cloudflare) RRSets(ctx context.Context, _, id string) ([]RRSet, error)

func (*Cloudflare) SetRRSet

func (c *Cloudflare) SetRRSet(ctx context.Context, zone, id string, set RRSet) error

type CloudflareSettings

type CloudflareSettings struct {
	Token     string `json:"token"`
	AccountID string `json:"account_id"`
}

CloudflareSettings configure the Cloudflare API.

type PowerDNS

type PowerDNS struct {
	URL         string // e.g. http://127.0.0.1:8081
	APIKey      string
	ServerID    string   // default "localhost"
	Nameservers []string // NS records for new zones, e.g. ns1.example.com.
	Client      *http.Client
}

PowerDNS talks to the PowerDNS Authoritative HTTP API.

func (*PowerDNS) CreateZone

func (p *PowerDNS) CreateZone(ctx context.Context, zone string) (string, []string, error)

CreateZone creates a Native zone with the configured nameservers.

func (*PowerDNS) DeleteRRSet

func (p *PowerDNS) DeleteRRSet(ctx context.Context, zone, _, name, typ string) error

func (*PowerDNS) DeleteZone

func (p *PowerDNS) DeleteZone(ctx context.Context, zone, _ string) error

func (*PowerDNS) RRSets

func (p *PowerDNS) RRSets(ctx context.Context, zone, _ string) ([]RRSet, error)

func (*PowerDNS) SetRRSet

func (p *PowerDNS) SetRRSet(ctx context.Context, zone, _ string, set RRSet) error

type PowerDNSSettings

type PowerDNSSettings struct {
	URL         string   `json:"url"`
	APIKey      string   `json:"api_key"`
	ServerID    string   `json:"server_id"`
	Nameservers []string `json:"nameservers"`
}

PowerDNSSettings configure the PowerDNS API.

type Provider

type Provider interface {
	// CreateZone creates a zone and returns the provider's ID for it and its nameservers.
	CreateZone(ctx context.Context, zone string) (remoteID string, nameservers []string, err error)
	DeleteZone(ctx context.Context, zone, remoteID string) error
	// RRSets lists the zone's records (SOA included when the provider exposes it).
	RRSets(ctx context.Context, zone, remoteID string) ([]RRSet, error)
	// SetRRSet replaces all records of set.Name/set.Type.
	SetRRSet(ctx context.Context, zone, remoteID string, set RRSet) error
	DeleteRRSet(ctx context.Context, zone, remoteID, name, typ string) error
}

Provider is an authoritative DNS service.

type RRSet

type RRSet struct {
	Name    string   `json:"name"` // fully qualified, trailing dot
	Type    string   `json:"type"`
	TTL     int      `json:"ttl"`
	Records []string `json:"records"`
}

RRSet is all records of one name and type.

type Settings

type Settings struct {
	Provider   string             `json:"provider"` // "" (off) | powerdns | cloudflare
	PowerDNS   PowerDNSSettings   `json:"powerdns"`
	Cloudflare CloudflareSettings `json:"cloudflare"`
	// Customers may create zones only for domains of their websites; admins for any domain.
	AutoRecords bool `json:"auto_records"` // add A records for website domains in hosted zones
}

Settings are the panel's DNS settings (stored as JSON under the "dns" key).

func (Settings) New

func (s Settings) New() Provider

New returns the configured provider, or nil when DNS hosting is off.

func (*Settings) Validate

func (s *Settings) Validate() error

Validate normalises and checks settings.

Jump to

Keyboard shortcuts

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