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 ¶
- Variables
- func Fqdn(name string) string
- func InZone(name, zone string) bool
- func Normalize(zone string, set *RRSet) error
- func QuoteTXT(v string) string
- func UnquoteTXT(v string) string
- func ValidName(name string) bool
- func ValidZone(zone string) bool
- type Cloudflare
- func (c *Cloudflare) CreateZone(ctx context.Context, zone string) (string, []string, error)
- func (c *Cloudflare) DeleteRRSet(ctx context.Context, _, id, name, typ string) error
- func (c *Cloudflare) DeleteZone(ctx context.Context, _, id string) error
- func (c *Cloudflare) RRSets(ctx context.Context, _, id string) ([]RRSet, error)
- func (c *Cloudflare) SetRRSet(ctx context.Context, zone, id string, set RRSet) error
- type CloudflareSettings
- type PowerDNS
- func (p *PowerDNS) CreateZone(ctx context.Context, zone string) (string, []string, error)
- func (p *PowerDNS) DeleteRRSet(ctx context.Context, zone, _, name, typ string) error
- func (p *PowerDNS) DeleteZone(ctx context.Context, zone, _ string) error
- func (p *PowerDNS) RRSets(ctx context.Context, zone, _ string) ([]RRSet, error)
- func (p *PowerDNS) SetRRSet(ctx context.Context, zone, _ string, set RRSet) error
- type PowerDNSSettings
- type Provider
- type RRSet
- type Settings
Constants ¶
This section is empty.
Variables ¶
var ErrExists = errors.New("the DNS provider already has this zone")
ErrExists is returned when the provider already has the zone.
var ErrNotFound = errors.New("zone not found at the DNS provider")
ErrNotFound is returned for a zone the provider does not know.
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 Normalize ¶
Normalize validates and canonicalises a record set for zone (both fully qualified). A relative name ("www", "@") is completed with the zone.
func QuoteTXT ¶
QuoteTXT turns text into a quoted TXT content, split into 255-byte strings. Already quoted input is kept.
func UnquoteTXT ¶
UnquoteTXT reverses QuoteTXT (for providers that take plain text).
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 (*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
type CloudflareSettings ¶
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 ¶
CreateZone creates a Native zone with the configured nameservers.
func (*PowerDNS) DeleteRRSet ¶
func (*PowerDNS) DeleteZone ¶
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).