Documentation
¶
Overview ¶
Package cloudns implements the libdns interfaces for the ClouDNS HTTP API, allowing DNS records in ClouDNS-hosted zones to be listed, created, updated, and deleted.
The provider authenticates with the ClouDNS API using an API user ID (auth-id), an API sub-user ID (sub-auth-id), or an API sub-user name (sub-auth-user), together with the API password. API users are managed in the ClouDNS control panel under "API & Resellers".
Index ¶
- Constants
- 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)
Constants ¶
const ( // DefaultOperationRetries is the default maximum number of attempts // for each API call (the first try plus retries). DefaultOperationRetries = 5 // DefaultInitialBackoff is the default delay before the first retry; // it doubles after every failed attempt. DefaultInitialBackoff = 1 * time.Second // DefaultMaxBackoff is the default upper bound for the retry delay. DefaultMaxBackoff = 30 * time.Second )
Default retry configuration, applied when the corresponding Provider fields are left at their zero values.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider struct {
// AuthId is the ClouDNS API user ID ("auth-id").
AuthId string `json:"auth_id,omitempty"`
// SubAuthId is the ClouDNS API sub-user ID ("sub-auth-id").
// It is consulted only if AuthId is empty.
SubAuthId string `json:"sub_auth_id,omitempty"`
// SubAuthUser is the ClouDNS API sub-user name ("sub-auth-user").
// It is consulted only if AuthId and SubAuthId are empty.
SubAuthUser string `json:"sub_auth_user,omitempty"`
// AuthPassword is the password of the API user or sub-user.
AuthPassword string `json:"auth_password"`
// OperationRetries is the maximum number of attempts for each API
// call. Only transient failures (network errors, HTTP 429, and
// HTTP 5xx responses) are retried. Defaults to DefaultOperationRetries.
OperationRetries int `json:"operation_retries,omitempty"`
// InitialBackoff is the delay before the first retry; it doubles
// after every failed attempt. Defaults to DefaultInitialBackoff.
InitialBackoff time.Duration `json:"initial_backoff,omitempty"`
// MaxBackoff caps the exponentially growing retry delay.
// Defaults to DefaultMaxBackoff.
MaxBackoff time.Duration `json:"max_backoff,omitempty"`
// BaseURL overrides the ClouDNS API endpoint. Defaults to
// "https://api.cloudns.net/dns/". Mainly useful for testing.
BaseURL string `json:"-"`
// HTTPClient overrides the HTTP client used for API requests.
// Defaults to a client with a 30-second timeout.
HTTPClient *http.Client `json:"-"`
// contains filtered or unexported fields
}
Provider facilitates DNS record manipulation with ClouDNS.
Exactly one of AuthId, SubAuthId, or SubAuthUser must be set, along with AuthPassword. All other fields are optional.
The zero value of each optional field means "use the default". A Provider must not be copied after first use, and its configuration fields must not be modified after the first method call. Its methods are safe for concurrent use: SetRecords and DeleteRecords serialize their read-modify-write cycles per Provider instance, so simultaneous calls see each other's changes. (Calls made through separate Provider instances or processes are not synchronized.)
func (*Provider) AppendRecords ¶
func (p *Provider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)
AppendRecords adds records to the zone and returns the records that were created. It never modifies or deletes existing records.
The operation is not atomic: records are created one at a time, in order. If a record fails to be created, the records created so far are returned together with the error.
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 exactly match the input records, and returns the records that were deleted. Input records that do not exist in the zone are silently ignored.
As allowed by the libdns specification, the type, TTL, and data of an input record may be left as their zero values to match any value of that field; the name must always be specified ("@" for the zone apex).
The operation is not atomic: records are deleted one at a time, and if a deletion fails, the records deleted so far are returned together with the error.
func (*Provider) GetRecords ¶
GetRecords lists all the records in the zone.
Records of types not modeled by the libdns package (for example WR or NAPTR) are returned as generic libdns.RR values whose Data holds the primary "record" field reported by ClouDNS.
func (*Provider) ListZones ¶ added in v1.2.0
ListZones returns all DNS zones managed by this account, using pagination as required by the ClouDNS API.
func (*Provider) SetRecords ¶
func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)
SetRecords updates the zone so that the records provided in the input are the only records of their (name, type) RRset. RRsets not named in the input are left untouched. It returns the records that are now present in the affected RRsets.
ClouDNS does not offer batch or atomic operations, so SetRecords is NOT atomic: if an error occurs partway, the zone may be left with some changes applied and others not. No rollback is attempted. All planned operations are attempted even if one of them fails, and all errors are joined and returned.