Documentation
¶
Overview ¶
Package njalla implements the libdns interfaces for Njalla (https://njal.la), allowing DNS records to be managed through the Njalla JSON-RPC API.
Index ¶
- func IsNotFound(err error) bool
- type APIError
- type HTTPClient
- type Provider
- func (p *Provider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)
- func (p *Provider) DeleteRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)
- func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error)
- func (p *Provider) ListZones(ctx context.Context) ([]libdns.Zone, error)
- func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)
- type RecordID
- type RetryConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNotFound ¶
IsNotFound reports whether err is a Njalla 404. The remove-record method returns this when no record matched the supplied fields, which the libdns RecordDeleter contract requires us to treat as "nothing to do" rather than as a failure.
Types ¶
type APIError ¶
APIError is returned when Njalla reports a JSON-RPC error. Callers can use errors.As to inspect the code, and IsNotFound to detect the specific "not found" response that remove-record returns when nothing matched.
type HTTPClient ¶
HTTPClient is the subset of http.Client used by this package. Providing a custom implementation is useful for tests and for callers that need control over transports, proxies, or timeouts.
type Provider ¶
type Provider struct {
// APIToken is the Njalla API token used for authentication. Tokens are
// created from the Njalla account settings page.
//
// The token needs the add-record, edit-record, remove-record, and
// list-records methods. A token created with Njalla's "acme" option
// covers the ACME DNS-01 challenge, but restricts listing to the
// _acme-challenge prefix.
APIToken string `json:"api_token,omitempty"`
// HTTPClient is used for API requests. If nil, a client with a 30 second
// timeout is used.
HTTPClient HTTPClient `json:"-"`
// contains filtered or unexported fields
}
Provider facilitates DNS record manipulation with Njalla.
Record types ¶
A, AAAA, CAA, CNAME, MX, NS, SRV, TXT, HTTPS, and SVCB records are returned as the corresponding concrete libdns types. Any other type, including Njalla's proprietary Redirect and Dynamic pseudo-types, is returned as an opaque libdns.RR. Records of any type may be supplied as input.
Provider-specific behaviour ¶
Values are stored exactly as supplied. Njalla preserves trailing dots on CNAME, NS, MX, and SRV targets rather than normalising them, and matches on them byte-for-byte, so this package does not rewrite them either.
A TTL of 0 leaves the TTL unset, which Njalla defaults to 10800 seconds. Use a sub-second duration to request a TTL of 0, as described by libdns.RR.
Njalla rejects a few otherwise-valid records: TXT values that are empty or contain a double quote, and MX records with a preference of 0. These are reported as errors before the API is called.
DNSSEC records are not returned by GetRecords and are not supported by SetRecords.
Atomicity ¶
The Njalla API offers no batch operations, so AppendRecords, SetRecords, and DeleteRecords are not atomic. If one of them returns an error, some of the requested changes may already have been applied; the records that were successfully changed are returned alongside the error.
All methods are safe for concurrent use.
func (*Provider) AppendRecords ¶
func (p *Provider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)
AppendRecords adds records to the zone, leaving existing records untouched. It returns the records that were created.
func (*Provider) DeleteRecords ¶
func (p *Provider) DeleteRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)
DeleteRecords deletes records from the zone, returning those that were deleted. Records that do not exist are silently ignored.
Deletion matches on name, type, and value. Leaving the value empty deletes every record with that name and type, and leaving the type empty deletes every record with that name; per the libdns contract, TTL is not part of the match. Njalla performs the matching itself, so no listing is required and this works with tokens that are restricted to the ACME challenge prefix. The one exception is deleting by name alone, which needs a listing because the API requires a type.
func (*Provider) GetRecords ¶
GetRecords lists all the records in the zone.
DNSSEC-related records are not included. Record types libdns does not model are returned as libdns.RR.
func (*Provider) SetRecords ¶
func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)
SetRecords makes the given records the complete contents of their RRsets.
For every (name, type) pair present in the input, the records supplied become the only records in the zone with that name and type: surplus records are deleted and missing ones created. Records with other names or types are left alone. Existing record IDs are reused where possible, so an RRset is never momentarily empty.
DNSSEC records are not supported.
type RecordID ¶
type RecordID string
RecordID is the Njalla-assigned identifier for a record. It is attached to every record this package returns via the libdns ProviderData field, so that later calls can address the record directly instead of searching for it.
ProviderData is not portable across providers or zones, and this package never depends on it for correctness: every operation works when it is absent. Records of types libdns models as the opaque libdns.RR struct cannot carry it at all, since RR has no ProviderData field.
type RetryConfig ¶
type RetryConfig struct {
MaxRetries int
BaseDelay time.Duration
MaxDelay time.Duration
RandomFactor float64
}
RetryConfig controls how transient failures are retried.
func DefaultRetryConfig ¶
func DefaultRetryConfig() RetryConfig
DefaultRetryConfig returns the retry policy used when none is configured. libdns asks implementations to recover from connection errors, 5xx, and 429 without adding substantial latency, so the ceiling is deliberately low.