regfish

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 9 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

regfish for libdns

Go Reference

This package implements the libdns interfaces for the regfish DNS API, allowing you to manage DNS records.

Configuration

The provider needs a regfish API key (regfish dash: Account, Security, API keys):

provider := &regfish.Provider{APIToken: os.Getenv("REGFISH_API_KEY")}

In JSON the key is api_token:

{ "api_token": "REGFISH_API_KEY" }

Before this field carried a JSON tag the key was APIToken. Adjust configurations that still use it.

Record types

Type libdns type Notes
A, AAAA libdns.Address
TXT libdns.TXT
CNAME libdns.CNAME
MX libdns.MX
SRV libdns.SRV
CAA libdns.CAA
ALIAS, TLSA libdns.RR TLSA data is usage selector matching-type hex
NS and others libdns.RR or libdns.NS read only, the API does not write them

A generic libdns.RR is parsed into its specific type before it is sent, so libdns.RR{Type: "MX", Data: "10 mail.example.com."} works like the typed record.

Target hosts (CNAME, MX, SRV, ALIAS) are sent fully qualified. A target without a trailing dot is taken to be fully qualified already.

The API accepts TTLs from 60 to 86400 seconds. A record without a TTL gets the API default of 86400 seconds.

Behaviour

  • AppendRecords creates records. A record with the same name, type and value as an existing one is rejected by the API.
  • SetRecords makes the input the only members of its RRsets: for every name and type in the input, other records of that name and type are removed. A record that only needs a new value is updated in place. The API has no transactions, so the change is applied record by record.
  • DeleteRecords deletes matching records. Type, TTL and value act as wildcards when left empty, and records that do not exist are ignored. The name must always be given, use @ for the zone apex.
  • Records regfish manages itself (the API reports them as auto) are protected: a wildcard delete skips them, and SetRecords refuses an RRset in which it would have to replace one. Deleting such a record by its exact type and value works.
  • Every call validates its whole input before the first write. A record without a name or with a name outside of the zone is rejected.
  • The API finds the zone from the record name. Asked for a sub-domain of a zone, the provider only reads and changes records at or below that sub-domain.
  • The API identifies a record by name, type and value. Two MX records with the same target and different priorities cannot exist side by side.
  • Errors carry the HTTP status and the message of the API, for example status code 417: Resource record already exists.

All methods honour the context and are safe for concurrent use.

Testing

go test ./... runs against an in-memory stand-in for the API and needs no credentials.

The integration test talks to the live API and writes real records below libdns-test in a zone of your account, which it removes again:

RF_API_KEY=... RF_TEST_ZONE=example.com go test -tags integration -run TestIntegration -v

Notes

This project was authored to support the needs of Caddy Server, see caddy-dns/regfish.

Documentation

Overview

Package regfish implements a DNS record management client compatible with the libdns interfaces for regfish.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// APIToken is a regfish API key (regfish dash: Account, Security, API keys).
	APIToken string `json:"api_token,omitempty"`
	// contains filtered or unexported fields
}

Provider facilitates DNS record manipulation with regfish.

func (*Provider) AppendRecords

func (p *Provider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

AppendRecords adds records to the zone. It returns the records that were added.

func (*Provider) DeleteRecords

func (p *Provider) DeleteRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

DeleteRecords deletes the records from the zone that match the input. Type, TTL and value act as wildcards when left empty; the name must always be given. Input records that do not exist in the zone are ignored. It returns the records that were deleted.

A record managed by regfish itself (one the API reports as "auto") is only deleted when the input names its type and value. A wildcard never removes it.

func (*Provider) GetRecords

func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error)

GetRecords lists all the records in the zone.

func (*Provider) SetRecords

func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

SetRecords makes the input records the only members of their RRsets: for every (name, type) pair in the input, records of that pair which are not part of the input are removed, and missing ones are created. Records of other names or types are left alone. It returns the records that were set.

The input is checked completely before the first write. SetRecords refuses to work on an RRset that contains a record managed by regfish itself (one the API reports as "auto") unless that record already has a wanted value.

The API has no transaction, so the change is applied record by record. A record that only needs a different value is updated in place rather than deleted and re-created, which keeps a single-record RRset resolvable throughout. If a request fails midway, the records set so far are returned together with the error.

Jump to

Keyboard shortcuts

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