Categorygithub.com/joeig/go-powerdns/v3
modulepackage
3.14.1
Repository: https://github.com/joeig/go-powerdns.git
Documentation: pkg.go.dev

# README

PowerDNS 4.x API bindings for Golang

This community project provides bindings for PowerDNS Authoritative Server. It's not associated with the official PowerDNS product itself.

Test coverage CodeQL Go Report Card PkgGoDev

Features

Conveniently manage

It works entirely with the Go standard library and can easily be customized.1

For more features, consult our documentation.

Setup

go get -u github.com/joeig/go-powerdns/v3
import "github.com/joeig/go-powerdns/v3"

Usage

Initialize the handle

import (
	"github.com/joeig/go-powerdns/v3"
	"context"
)

// Let's say
// * PowerDNS Authoritative Server is listening on `http://localhost:80`,
// * the virtual host is `localhost` and
// * the API key is `apipw`.
pdns := powerdns.New("http://localhost:80", "localhost", powerdns.WithAPIKey("apipw"))

// All API interactions support a Go context, which allow you to pass cancellation signals and deadlines.
// If you don't need a context, `context.Background()` would be the right choice for the following examples.
// If you want to learn more about how context helps you to build reliable APIs, see: https://go.dev/blog/context
ctx := context.Background()

Migrate NewClient to New

If you have used NewClient before and want to migrate to New, please see the release notes for v3.13.0.

Get/add/change/delete zones

zones, err := pdns.Zones.List(ctx)
zone, err := pdns.Zones.Get(ctx, "example.com")
export, err := pdns.Zones.Export(ctx, "example.com")
zone, err := pdns.Zones.AddNative(ctx, "example.com", true, "", false, "foo", "foo", true, []string{"ns.foo.tld."})
err := pdns.Zones.Change(ctx, "example.com", &zone)
err := pdns.Zones.Delete(ctx, "example.com")

Add/change/delete resource records

err := pdns.Records.Add(ctx, "example.com", "www.example.com", powerdns.RRTypeAAAA, 60, []string{"::1"})
err := pdns.Records.Change(ctx, "example.com", "www.example.com", powerdns.RRTypeAAAA, 3600, []string{"::1"})
err := pdns.Records.Delete(ctx, "example.com", "www.example.com", powerdns.RRTypeA)
records, err := pdns.Records.Get(ctx, "example.com", "www.example.com", powerdns.RRTypePtr(powerdns.RRTypeA))

Request server information and statistics

statistics, err := pdns.Statistics.List(ctx)
servers, err := pdns.Servers.List(ctx)
server, err := pdns.Servers.Get(ctx, "localhost")

Handle DNSSEC cryptographic material

cryptokeys, err := pdns.Cryptokeys.List(ctx)
cryptokey, err := pdns.Cryptokeys.Get(ctx, "example.com", "1337")
err := pdns.Cryptokeys.Delete(ctx, "example.com", "1337")

Create/change/delete TSIG keys

tsigkey, err := pdns.TSIGKeys.Create(ctx, "examplekey", "hmac-sha256", "")
tsigkey, err := pdns.TSIGKeys.Change(ctx, "examplekey.", powerdns.TSIGKey{Key: powerdns.String("newkey")})
tsigkeys, err := pdns.TSIGKeys.List(ctx)
tsigkey, err := pdns.TSIGKeys.Get(ctx, "examplekey.")
err := pdns.TSIGKeys.Delete(ctx, "examplekey.")

More examples

There are several examples on pkg.go.dev.

Documentation

See pkg.go.dev for a full reference.

Setup

Requirements

Tested PowerDNS versions

Supported versions of PowerDNS Authoritative Server ("API v1"):

  • 4.7
  • 4.8
  • 4.9

Version 4.1, 4.2 and 4.3 are probably working fine, but are officially end-of-life. Be aware that there are breaking changes in "API v1" between PowerDNS 3.x, 4.0 and 4.1.

Tested Go versions

In accordance with Go's version support policy, this module is being tested with the following Go releases:

  • 1.22
  • 1.23

Contribution

This API client has not been completed yet, so feel free to contribute. The OpenAPI specification is a good reference.

You can use Docker Compose to launch a PowerDNS authoritative server including a generic SQLite3 backend, DNSSEC support and some optional fixtures:

docker-compose -f docker-compose-v4.9.yml up
docker-compose -f docker-compose-v4.9.yml exec powerdns sh init_docker_fixtures.sh

It's also possible to target mocks against this server, or any other PowerDNS instance which is running on http://localhost:8080.

make test-without-mocks

The mocks assume there is a vHost/Server ID called localhost and API key apipw.

Footnotes

  1. There is a dependency for github.com/jarcoal/httpmock, which is used by the test suite.

# Functions

Bool is a helper function that allocates a new bool value to store v and returns a pointer to it.
BoolValue is a helper function that returns the value of a bool pointer or false.
ChangeTypePtr is a helper function that allocates a new ChangeType value to store v and returns a pointer to it.
New initializes a new client instance.
NewClient initializes a new client instance.
RRTypePtr is a helper function that allocates a new RRType value to store v and returns a pointer to it.
String is a helper function that allocates a new string value to store v and returns a pointer to it.
StringValue is a helper function that returns the value of a bool pointer or "".
Uint32 is a helper function that allocates a new uint32 value to store v and returns a pointer to it.
Uint32Value is a helper function that returns the value of a bool pointer or 0.
Uint64 is a helper function that allocates a new uint64 value to store v and returns a pointer to it.
Uint64Value is a helper function that returns the value of a bool pointer or 0.
WithAPIKey is an option for New to set the API key.
WithComments defines a function to create a comment option for Add and Change methods.
WithHeaders is an option for New to set HTTP client headers.
WithHTTPClient is an option for New to set an HTTP client.
ZoneKindPtr is a helper function that allocates a new ZoneKind value to store v and returns a pointer to it.
ZoneTypePtr is a helper function that allocates a new ZoneType value to store v and returns a pointer to it.

# Constants

ChangeTypeDelete represents the DELETE change type.
ChangeTypeReplace represents the REPLACE change type.
ConsumerZoneKind sets the zone's kind to consumer.
MasterZoneKind sets the zone's kind to master.
NativeZoneKind sets the zone's kind to native.
ProducerZoneKind sets the zone's kind to producer.
RRTypeA represents the A resource record type.
RRTypeA6 represents the A6 resource record type.
RRTypeAAAA represents the AAAA resource record type.
RRTypeAFSDB represents the AFSDB resource record type.
RRTypeALIAS represents the ALIAS resource record type.
RRTypeCAA represents the CAA resource record type.
RRTypeCDNSKEY represents the CDNSKEY resource record type.
RRTypeCDS represents the CDS resource record type.
RRTypeCERT represents the CERT resource record type.
RRTypeCNAME represents the CNAME resource record type.
RRTypeDHCID represents the DHCID resource record type.
RRTypeDLV represents the DLV resource record type.
RRTypeDNAME represents the DNAME resource record type.
RRTypeDNSKEY represents the DNSKEY resource record type.
RRTypeDS represents the DS resource record type.
RRTypeEUI48 represents the EUI48 resource record type.
RRTypeEUI64 represents the EUI64 resource record type.
RRTypeHINFO represents the HINFO resource record type.
RRTypeIPSECKEY represents the IPSECKEY resource record type.
RRTypeKEY represents the KEY resource record type.
RRTypeKX represents the KX resource record type.
RRTypeLOC represents the LOC resource record type.
RRTypeLUA represents the LUA resource record type.
RRTypeMAILA represents the MAILA resource record type.
RRTypeMAILB represents the MAILB resource record type.
RRTypeMINFO represents the MINFO resource record type.
RRTypeMR represents the MR resource record type.
RRTypeMX represents the MX resource record type.
RRTypeNAPTR represents the NAPTR resource record type.
RRTypeNS represents the NS resource record type.
RRTypeNSEC represents the NSEC resource record type.
RRTypeNSEC3 represents the NSEC3 resource record type.
RRTypeNSEC3PARAM represents the NSEC3PARAM resource record type.
RRTypeOPENPGPKEY represents the OPENPGPKEY resource record type.
RRTypePTR represents the PTR resource record type.
RRTypeRKEY represents the RKEY resource record type.
RRTypeRP represents the RP resource record type.
RRTypeRRSIG represents the RRSIG resource record type.
RRTypeSIG represents the SIG resource record type.
RRTypeSMIMEA represents the SMIMEA resource record type.
RRTypeSOA represents the SOA resource record type.
RRTypeSPF represents the SPF resource record type.
RRTypeSRV represents the SRV resource record type.
RRTypeSSHFP represents the SSHFP resource record type.
RRTypeTKEY represents the TKEY resource record type.
RRTypeTLSA represents the TLSA resource record type.
RRTypeTSIG represents the TSIG resource record type.
RRTypeTXT represents the TXT resource record type.
RRTypeURI represents the URI resource record type.
RRTypeWKS represents the WKS resource record type.
SlaveZoneKind sets the zone's kind to slave.
ZoneZoneType sets the zone's type to zone.

# Structs

AxfrRetrieveResult structure with JSON API metadata.
CacheFlushResult structure with JSON API metadata.
Client configuration structure.
Comment structure with JSON API metadata.
ConfigSetting structure with JSON API metadata.
Cryptokey structure with JSON API metadata.
Error structure with JSON API metadata.
NotifyResult structure with JSON API metadata.
Record structure with JSON API metadata.
RRset structure with JSON API metadata.
RRsets structure with JSON API metadata.
Server structure with JSON API metadata.
Statistic structure with JSON API metadata.
TSIGKey structure with JSON API metadata.
Zone structure with JSON API metadata.

# Type aliases

ChangeType represents a string-valued change type.
ConfigService handles communication with the zones related methods of the Client API.
CryptokeysService handles communication with the cryptokeys related methods of the Client API.
Export string type.
NewOption is a functional option for New.
RecordsService handles communication with the records related methods of the Client API.
RRType represents a string-valued resource record type.
ServersService handles communication with the servers related methods of the Client API.
StatisticsService handles communication with the statistics related methods of the Client API.
TSIGKeysService handles communication with the tsigs related methods of the Client API.
ZoneKind string type.
ZonesService handles communication with the zones related methods of the Client API.
ZoneType string type.