regfish for libdns
This package implements the libdns interfaces for the regfish DNS API, allowing you to manage DNS records.
The provider needs a regfish API key (regfish dash: Account, Security, API keys):
provider := ®fish.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.
| 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.
AppendRecordscreates records. A record with the same name, type and value as an existing one is rejected by the API.SetRecordsmakes 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.DeleteRecordsdeletes 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, andSetRecordsrefuses 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.
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
This project was authored to support the needs of Caddy Server, see caddy-dns/regfish.