dynu

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2025 License: MIT Imports: 15 Imported by: 3

README

Dynu for libdns

Go Reference

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

Authenticating

This package uses API Token authentication. Refer to the Dynu documentation for more information.

Start by retrieving your API token (API-Key) from the table on the API Credentials page to be able to make authenticated requests to the API.

OwnDomain field

The field OwnDomain was added to support the Caddy DNS module use case where the DNS zone (e.g. dynu.com) is different from your own (sub)domain in Dynu (e.g. my.dynu.com). Just set it to the root domain in Dynu API, e.g. domainName in the response of /dns/getroot/{hostname} call.

Implementation notes

v0.1.0 of this package relied on the DNS record ID generated by Dynu to function.

Since libdns v1.0.0, the ID field was removed from libdns interface and this package was updated to support operations without the ID. To reduce API calls, the ID field is now moved into a DynuProviderData struct in the ProviderData field of concrete DNS record types.

This change should be transparent. However, it should be noted that when an ID is supplied, at most 1 record will be updated/deleted; when no ID is supplied, Type+Name (for update) and Type+Name+Data (for update) will be used for the search and more than 1 records may be updated/deleted.

A, AAAA, CAA, CNAME, MX, NS, SRV and TXT records returned by this package will have ID information by default. To remove the ID, call the .RR() methods on the returned objects.

Tests

Several tests for the basic functionality of the real Dynu API are available. These tests are not run by default. Set the environment variables TEST_ZONE and TEST_API_TOKEN to enable the tests like so:

TEST_ZONE=example.com. TEST_API_TOKEN=dynu_api_token go test -v

If the tests fail, you can manually check and fix the DNS records on the DDNS Services page.

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIException

type APIException struct {
	StatusCode int32  `json:"statusCode,omitempty"`
	Type       string `json:"type,omitempty"`
	Message    string `json:"message,omitempty"`
}

func (APIException) Error

func (a APIException) Error() string

type Client

type Client struct {
	HTTPClient *http.Client
	APIToken   string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(APIToken string) *Client

func (*Client) AddRecord added in v1.0.0

func (c *Client) AddRecord(ctx context.Context, hostnameId int64, record DNSRecord) (*DNSRecord, error)

func (*Client) DeleteRecord

func (c *Client) DeleteRecord(ctx context.Context, hostnameId int64, dnsRecordId string) error

func (*Client) DeleteRecords added in v1.0.0

func (c *Client) DeleteRecords(ctx context.Context, hostnameId int64, rrType string, nodeName string, data string) error

func (*Client) GetRecords

func (c *Client) GetRecords(ctx context.Context, hostnameId int64) ([]DNSRecord, error)

func (*Client) GetRootDomain

func (c *Client) GetRootDomain(ctx context.Context, hostname string) (*DNSHostname, error)

type DNSHostname

type DNSHostname struct {
	StatusCode int32  `json:"statusCode,omitempty"`
	ID         int64  `json:"id,omitempty"`
	DomainName string `json:"domainName,omitempty"`
	Hostname   string `json:"hostname,omitempty"`
	Node       string `json:"node,omitempty"`
}

type DNSRecord

type DNSRecord struct {
	ID          int64  `json:"id,omitempty"`
	Type        string `json:"recordType,omitempty"`
	DomainID    int64  `json:"domainId,omitempty"`
	DomainName  string `json:"domainName,omitempty"`
	NodeName    string `json:"nodeName,omitempty"`
	Hostname    string `json:"hostname,omitempty"`
	State       bool   `json:"state,omitempty"`
	Content     string `json:"content,omitempty"`
	Ipv4Address string `json:"ipv4Address,omitempty"`
	Ipv6Address string `json:"ipv6Address,omitempty"`
	Host        string `json:"host,omitempty"`
	TextData    string `json:"textData,omitempty"`
	TTL         int    `json:"ttl,omitempty"`
	Priority    int    `json:"priority,omitempty"`
	Flags       int    `json:"flags,omitempty"`
	Tag         string `json:"tag,omitempty"`
	Value       string `json:"value,omitempty"`
	Weight      int    `json:"weight,omitempty"`
	Port        int    `json:"port,omitempty"`
	StatusCode  int32  `json:"statusCode,omitempty"`
}

type DeleteResponse

type DeleteResponse struct {
	StatusCode int32 `json:"statusCode,omitempty"`
}

type DynuProviderData added in v1.0.0

type DynuProviderData struct {
	ID       int64 `json:"id,omitempty"`
	DomainID int64 `json:"domainId,omitempty"`
}

type Provider

type Provider struct {
	// config fields (with snake_case json struct tags on exported fields)
	APIToken  string `json:"api_token,omitempty"`
	OwnDomain string `json:"own_domain,omitempty"`

	Once   sync.Once
	Client *Client
}

Provider facilitates DNS record manipulation with dynu.

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. It returns the records that were deleted.

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 sets the records in the zone, either by updating existing records or creating new ones. It returns the updated records.

type RecordsResponse

type RecordsResponse struct {
	StatusCode int32       `json:"statusCode,omitempty"`
	DNSRecords []DNSRecord `json:"dnsRecords,omitempty"`
}

type UpdateResponse

type UpdateResponse struct {
	StatusCode int32 `json:"statusCode,omitempty"`
	ID         int64 `json:"id,omitempty"`
}

Jump to

Keyboard shortcuts

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