noderings

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 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

NodeRings for libdns

Go Reference

This package implements the libdns interfaces for NodeRings DNS, allowing you to manage DNS records. NodeRings serves zones from anycast nameservers (ans1.nrings.io, ans2.nrings.io).

It implements RecordGetter, RecordAppender, RecordSetter, RecordDeleter and ZoneLister.

Configuration

Field JSON Environment default Description
APIToken api_token NODERINGS_API_TOKEN Required. A NodeRings user API token or service account token with access to the zone.
OrganizationID organization_id NODERINGS_ORGANIZATION_ID Only needed when the token belongs to more than one organization.
BaseURL base_url NODERINGS_API_URL API base URL. Default https://api.noderings.com.
HTTPClient – – Optional *http.Client. Default: 30 s timeout.

Environment variables are used only when the field is empty.

Example

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/libdns/libdns"
	"github.com/libdns/noderings"
)

func main() {
	p := &noderings.Provider{APIToken: "YOUR_TOKEN"}
	ctx := context.Background()

	_, err := p.AppendRecords(ctx, "example.com.", []libdns.Record{
		libdns.TXT{Name: "_acme-challenge", TTL: 60 * time.Second, Text: "token"},
	})
	if err != nil {
		panic(err)
	}

	recs, err := p.GetRecords(ctx, "example.com.")
	if err != nil {
		panic(err)
	}
	fmt.Println(recs)
}

Caveats

  • Record sets. NodeRings stores all records with the same name and type as one record set with one TTL. AppendRecords adds to an existing set and keeps its TTL. SetRecords rejects input that gives one set two different TTLs.
  • Concurrency. Changes go through read-modify-write of the record set. Calls on one Provider are serialized, so concurrent appends to the same name (for example the two TXT values of a wildcard certificate) both land. Separate Provider values or processes changing the same record set at the same moment can still race.
  • Atomicity. Changes are not atomic across record sets: if a call fails part-way, sets written before the failure keep their new contents.
  • TTL. NodeRings accepts TTLs from 30 seconds to one day. Shorter TTLs (including 0, "do not cache") are stored as 30 seconds, longer ones as 86400 seconds.
  • TXT values. Values longer than 255 bytes are split into several character-strings and joined again when read.
  • DNSSEC. DNSSEC records are managed by NodeRings and are not returned by the API.
  • Retries. Connection errors, HTTP 429 and HTTP 5xx are retried 3 times (about 2.5 s in total), and context cancellation is honoured.

Tests

go test ./...

TestLive runs against the real API when NODERINGS_API_TOKEN and NODERINGS_TEST_ZONE (for example example.com.) are set. It creates and removes two TXT values under _libdns-test.

The provider also passes the shared libdnstest suite (all record types, run against the production API).

Documentation

Overview

Package noderings implements a DNS record management client compatible with the libdns interfaces for NodeRings DNS (https://noderings.com).

NodeRings stores records as record sets: all records with the same name and type share one TTL and are written together. AppendRecords, SetRecords and DeleteRecords therefore read the affected record sets, change them and write them back. Calls on one Provider are serialized so concurrent changes to the same record set (for example the two TXT values of a wildcard certificate) cannot overwrite each other. Changes are not atomic across record sets: if a call fails, record sets written before the failure keep their new contents.

DNSSEC records are managed by NodeRings and are not returned by the API.

Index

Constants

View Source
const (
	EnvAPIToken       = "NODERINGS_API_TOKEN"
	EnvOrganizationID = "NODERINGS_ORGANIZATION_ID"
	EnvAPIURL         = "NODERINGS_API_URL"
)

Environment variables used when the matching Provider field is empty.

View Source
const DefaultAPIURL = "https://api.noderings.com"

DefaultAPIURL is the NodeRings API used when BaseURL is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int
	Message    string
}

APIError is an error answer from the NodeRings API.

func (*APIError) Error

func (e *APIError) Error() string

type Provider

type Provider struct {
	// APIToken is a NodeRings user API token or service account token.
	// Defaults to $NODERINGS_API_TOKEN.
	APIToken string `json:"api_token,omitempty"`

	// OrganizationID selects the organization when the token belongs to more
	// than one. Defaults to $NODERINGS_ORGANIZATION_ID.
	OrganizationID string `json:"organization_id,omitempty"`

	// BaseURL of the NodeRings API. Defaults to $NODERINGS_API_URL, then
	// https://api.noderings.com.
	BaseURL string `json:"base_url,omitempty"`

	// HTTPClient used for API calls. Defaults to a client with a 30s timeout.
	HTTPClient *http.Client `json:"-"`
	// contains filtered or unexported fields
}

Provider facilitates DNS record manipulation with NodeRings DNS.

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. Records that already exist are left as they are and not returned. A record set that already exists keeps its TTL.

func (*Provider) DeleteRecords

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

DeleteRecords deletes the specified records from the zone. It returns the records that were deleted. Type, TTL and value may be left empty to match any.

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) ListZones

func (p *Provider) ListZones(ctx context.Context) ([]libdns.Zone, error)

ListZones lists the zones the token can manage.

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. For each (name, type) in the input, the input records become the only records of that set. All input records with the same name and type must have the same TTL. It returns the records that were set.

Jump to

Keyboard shortcuts

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