powerdns

package module
v3.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 10 Imported by: 7

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.

Build Status Test coverage Go Report Card PkgGoDev

Features

  • Zone handling
  • Resource record handling
  • Server statistics gathering
  • DNSSEC handling

For more features, consult our documentation.

Usage

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

pdns := powerdns.NewClient("http://localhost:80", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)

Assuming that the server is listening on http://localhost:80 for virtual host localhost, the API password is apipw and you want to edit the domain example.com.

Get/add/change/delete zones
ctx := context.Background()

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 tsigkeys
tsigkey, err := pdns.TSIGKey.Create(ctx, "examplekey", "hmac-sha256", "")
tsigkey, err := pdns.TSIGKey.Change(ctx, "examplekey.", powerdns.TSIGKey{
	Key: powerdns.String("newkey"),
})
tsigkeys, err := pdns.TSIGKey.List(ctx)
tsigkey, err := pdns.TSIGKey.Get(ctx, "examplekey.")
err := pdns.TSIGKey.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.6
  • 4.7
  • 4.8

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.21
  • 1.22

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.8.yml up
docker-compose -f docker-compose-v4.8.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.

Documentation

Overview

Example
domain := fmt.Sprintf("%d.example.com.", rand.Int())
pdns := powerdns.NewClient("http://localhost:8080", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)
ctx := context.Background()

// Create a native zone
zone, err := pdns.Zones.AddNative(ctx, domain, false, "", false, "", "", true, []string{"localhost."})
if err != nil {
	log.Fatalf("%v", err)
}

o, _ := json.MarshalIndent(zone, "", "\t")
log.Printf("Zone: %s\n\n", o)

// Add and change an A record
if err := pdns.Records.Add(ctx, domain, fmt.Sprintf("www.%s", domain), powerdns.RRTypeA, 1337, []string{"127.0.0.9"}); err != nil {
	log.Fatalf("%v", err)
}
if err := pdns.Records.Change(ctx, domain, fmt.Sprintf("www.%s", domain), powerdns.RRTypeA, 42, []string{"127.0.0.10"}); err != nil {
	log.Fatalf("%v", err)
}

// update the existing record with a comment
comment := powerdns.Comment{
	Content:    powerdns.String("Example comment"),
	Account:    powerdns.String("example account"),
	ModifiedAt: powerdns.Uint64(uint64(time.Now().Unix())),
}
if err := pdns.Records.Change(ctx, domain, fmt.Sprintf("www.%s", domain), powerdns.RRTypeA, 42, []string{"127.0.0.10"}, powerdns.WithComments(comment)); err != nil {
	log.Fatalf("%v", err)
}

// Add a MX record with multiple values
if err := pdns.Records.Add(ctx, domain, domain, powerdns.RRTypeMX, 1337, []string{"10 mx1.example.com.", "20 mx2.example.com."}); err != nil {
	log.Fatalf("%v", err)
}

// Add a TXT record
if err := pdns.Records.Add(ctx, domain, fmt.Sprintf("www.%s", domain), powerdns.RRTypeTXT, 1337, []string{"\"foo1\""}); err != nil {
	log.Fatalf("%v", err)
}

// Create a TSIG Record
exampleKey, err := pdns.TSIGKey.Create(ctx, "examplekey", "hmac-sha256", "")
if err != nil {
	log.Fatalf("%v", err)
}

// Change a zone
zoneChangeSet := &powerdns.Zone{
	Account:          powerdns.String("test"),
	DNSsec:           powerdns.Bool(true),
	MasterTSIGKeyIDs: []string{*exampleKey.ID},
}

if err := pdns.Zones.Change(ctx, domain, zoneChangeSet); err != nil {
	log.Fatalf("%v", err)
}

// Retrieve zone attributes
changedZone, err := pdns.Zones.Get(ctx, domain)
if err != nil {
	log.Fatalf("%v", err)
}

o, _ = json.MarshalIndent(changedZone, "", "\t")
log.Printf("Changed zone: %q\n\n", o)
log.Printf("Account is %q and DNSsec is %t\n\n", powerdns.StringValue(changedZone.Account), powerdns.BoolValue(changedZone.DNSsec))
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper function that allocates a new bool value to store v and returns a pointer to it.

func BoolValue

func BoolValue(v *bool) bool

BoolValue is a helper function that returns the value of a bool pointer or false.

func String

func String(v string) *string

String is a helper function that allocates a new string value to store v and returns a pointer to it.

func StringValue

func StringValue(v *string) string

StringValue is a helper function that returns the value of a bool pointer or "".

func Uint32

func Uint32(v uint32) *uint32

Uint32 is a helper function that allocates a new uint32 value to store v and returns a pointer to it.

func Uint32Value

func Uint32Value(v *uint32) uint32

Uint32Value is a helper function that returns the value of a bool pointer or 0.

func Uint64

func Uint64(v uint64) *uint64

Uint64 is a helper function that allocates a new uint64 value to store v and returns a pointer to it.

func Uint64Value

func Uint64Value(v *uint64) uint64

Uint64Value is a helper function that returns the value of a bool pointer or 0.

func WithComments added in v3.9.0

func WithComments(comments ...Comment) func(*RRset)

WithComments defines a function to create a comment option for Add and Change methods

Types

type AxfrRetrieveResult added in v3.3.0

type AxfrRetrieveResult struct {
	Result *string `json:"result,omitempty"`
}

AxfrRetrieveResult structure with JSON API metadata

type CacheFlushResult

type CacheFlushResult struct {
	Count  *uint32 `json:"count,omitempty"`
	Result *string `json:"result,omitempty"`
}

CacheFlushResult structure with JSON API metadata

type ChangeType

type ChangeType string

ChangeType represents a string-valued change type

const (
	// ChangeTypeReplace represents the REPLACE change type
	ChangeTypeReplace ChangeType = "REPLACE"
	// ChangeTypeDelete represents the DELETE change type
	ChangeTypeDelete ChangeType = "DELETE"
)

func ChangeTypePtr

func ChangeTypePtr(v ChangeType) *ChangeType

ChangeTypePtr is a helper function that allocates a new ChangeType value to store v and returns a pointer to it.

type Client

type Client struct {
	Scheme   string
	Hostname string
	Port     string
	VHost    string
	Headers  map[string]string

	Config     *ConfigService
	Cryptokeys *CryptokeysService
	Records    *RecordsService
	Servers    *ServersService
	Statistics *StatisticsService
	Zones      *ZonesService
	TSIGKey    *TSIGKeyService
	// contains filtered or unexported fields
}

Client configuration structure

func NewClient

func NewClient(baseURL string, vHost string, headers map[string]string, httpClient *http.Client) *Client

NewClient initializes a new client instance

Example
_ = powerdns.NewClient("http://localhost:8080", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)
Output:

type Comment

type Comment struct {
	Content    *string `json:"content,omitempty"`
	Account    *string `json:"account,omitempty"`
	ModifiedAt *uint64 `json:"modified_at,omitempty"`
}

Comment structure with JSON API metadata

type ConfigService

type ConfigService service

ConfigService handles communication with the zones related methods of the Client API

func (*ConfigService) List

func (c *ConfigService) List(ctx context.Context) ([]ConfigSetting, error)

List retrieves a list of ConfigSettings

type ConfigSetting

type ConfigSetting struct {
	Name  *string `json:"name,omitempty"`
	Type  *string `json:"type,omitempty"`
	Value *string `json:"value,omitempty"`
}

ConfigSetting structure with JSON API metadata

type Cryptokey

type Cryptokey struct {
	Type       *string  `json:"type,omitempty"`
	ID         *uint64  `json:"id,omitempty"`
	KeyType    *string  `json:"keytype,omitempty"`
	Active     *bool    `json:"active,omitempty"`
	DNSkey     *string  `json:"dnskey,omitempty"`
	DS         []string `json:"ds,omitempty"`
	Privatekey *string  `json:"privatekey,omitempty"`
	Algorithm  *string  `json:"algorithm,omitempty"`
	Bits       *uint64  `json:"bits,omitempty"`
}

Cryptokey structure with JSON API metadata

type CryptokeysService

type CryptokeysService service

CryptokeysService handles communication with the cryptokeys related methods of the Client API

func (*CryptokeysService) Delete

func (c *CryptokeysService) Delete(ctx context.Context, domain string, id uint64) error

Delete removes a given Cryptokey

func (*CryptokeysService) Get

func (c *CryptokeysService) Get(ctx context.Context, domain string, id uint64) (*Cryptokey, error)

Get returns a certain Cryptokey instance of a given Zone

func (*CryptokeysService) List

func (c *CryptokeysService) List(ctx context.Context, domain string) ([]Cryptokey, error)

List retrieves a list of Cryptokeys that belong to a Zone

type Error

type Error struct {
	StatusCode int    `json:"-"`
	Status     string `json:"-"`
	Message    string `json:"error"`
}

Error structure with JSON API metadata

func (Error) Error

func (e Error) Error() string

type Export

type Export string

Export string type

type NotifyResult

type NotifyResult struct {
	Result *string `json:"result,omitempty"`
}

NotifyResult structure with JSON API metadata

type RRType

type RRType string

RRType represents a string-valued resource record type

const (
	// RRTypeA represents the A resource record type
	RRTypeA RRType = "A"
	// RRTypeAAAA represents the AAAA resource record type
	RRTypeAAAA RRType = "AAAA"
	// RRTypeA6 represents the A6 resource record type
	RRTypeA6 RRType = "A6"
	// RRTypeAFSDB represents the AFSDB resource record type
	RRTypeAFSDB RRType = "AFSDB"
	// RRTypeALIAS represents the ALIAS resource record type
	RRTypeALIAS RRType = "ALIAS"
	// RRTypeDHCID represents the DHCID resource record type
	RRTypeDHCID RRType = "DHCID"
	// RRTypeDLV represents the DLV resource record type
	RRTypeDLV RRType = "DLV"
	// RRTypeCAA represents the CAA resource record type
	RRTypeCAA RRType = "CAA"
	// RRTypeCERT represents the CERT resource record type
	RRTypeCERT RRType = "CERT"
	// RRTypeCDNSKEY represents the CDNSKEY resource record type
	RRTypeCDNSKEY RRType = "CDNSKEY"
	// RRTypeCDS represents the CDS resource record type
	RRTypeCDS RRType = "CDS"
	// RRTypeCNAME represents the CNAME resource record type
	RRTypeCNAME RRType = "CNAME"
	// RRTypeDNSKEY represents the DNSKEY resource record type
	RRTypeDNSKEY RRType = "DNSKEY"
	// RRTypeDNAME represents the DNAME resource record type
	RRTypeDNAME RRType = "DNAME"
	// RRTypeDS represents the DS resource record type
	RRTypeDS RRType = "DS"
	// RRTypeEUI48 represents the EUI48 resource record type
	RRTypeEUI48 RRType = "EUI48"
	// RRTypeEUI64 represents the EUI64 resource record type
	RRTypeEUI64 RRType = "EUI64"
	// RRTypeHINFO represents the HINFO resource record type
	RRTypeHINFO RRType = "HINFO"
	// RRTypeIPSECKEY represents the IPSECKEY resource record type
	RRTypeIPSECKEY RRType = "IPSECKEY"
	// RRTypeKEY represents the KEY resource record type
	RRTypeKEY RRType = "KEY"
	// RRTypeKX represents the KX resource record type
	RRTypeKX RRType = "KX"
	// RRTypeLOC represents the LOC resource record type
	RRTypeLOC RRType = "LOC"
	// RRTypeLUA represents the LUA resource record type
	RRTypeLUA RRType = "LUA"
	// RRTypeMAILA represents the MAILA resource record type
	RRTypeMAILA RRType = "MAILA"
	// RRTypeMAILB represents the MAILB resource record type
	RRTypeMAILB RRType = "MAILB"
	// RRTypeMINFO represents the MINFO resource record type
	RRTypeMINFO RRType = "MINFO"
	// RRTypeMR represents the MR resource record type
	RRTypeMR RRType = "MR"
	// RRTypeMX represents the MX resource record type
	RRTypeMX RRType = "MX"
	// RRTypeNAPTR represents the NAPTR resource record type
	RRTypeNAPTR RRType = "NAPTR"
	// RRTypeNS represents the NS resource record type
	RRTypeNS RRType = "NS"
	// RRTypeNSEC represents the NSEC resource record type
	RRTypeNSEC RRType = "NSEC"
	// RRTypeNSEC3 represents the NSEC3 resource record type
	RRTypeNSEC3 RRType = "NSEC3"
	// RRTypeNSEC3PARAM represents the NSEC3PARAM resource record type
	RRTypeNSEC3PARAM RRType = "NSEC3PARAM"
	// RRTypeOPENPGPKEY represents the OPENPGPKEY resource record type
	RRTypeOPENPGPKEY RRType = "OPENPGPKEY"
	// RRTypePTR represents the PTR resource record type
	RRTypePTR RRType = "PTR"
	// RRTypeRKEY represents the RKEY resource record type
	RRTypeRKEY RRType = "RKEY"
	// RRTypeRP represents the RP resource record type
	RRTypeRP RRType = "RP"
	// RRTypeRRSIG represents the RRSIG resource record type
	RRTypeRRSIG RRType = "RRSIG"
	// RRTypeSIG represents the SIG resource record type
	RRTypeSIG RRType = "SIG"
	// RRTypeSOA represents the SOA resource record type
	RRTypeSOA RRType = "SOA"
	// RRTypeSPF represents the SPF resource record type
	RRTypeSPF RRType = "SPF"
	// RRTypeSSHFP represents the SSHFP resource record type
	RRTypeSSHFP RRType = "SSHFP"
	// RRTypeSRV represents the SRV resource record type
	RRTypeSRV RRType = "SRV"
	// RRTypeTKEY represents the TKEY resource record type
	RRTypeTKEY RRType = "TKEY"
	// RRTypeTSIG represents the TSIG resource record type
	RRTypeTSIG RRType = "TSIG"
	// RRTypeTLSA represents the TLSA resource record type
	RRTypeTLSA RRType = "TLSA"
	// RRTypeSMIMEA represents the SMIMEA resource record type
	RRTypeSMIMEA RRType = "SMIMEA"
	// RRTypeTXT represents the TXT resource record type
	RRTypeTXT RRType = "TXT"
	// RRTypeURI represents the URI resource record type
	RRTypeURI RRType = "URI"
	// RRTypeWKS represents the WKS resource record type
	RRTypeWKS RRType = "WKS"
)

func RRTypePtr

func RRTypePtr(v RRType) *RRType

RRTypePtr is a helper function that allocates a new RRType value to store v and returns a pointer to it.

type RRset

type RRset struct {
	Name       *string     `json:"name,omitempty"`
	Type       *RRType     `json:"type,omitempty"`
	TTL        *uint32     `json:"ttl,omitempty"`
	ChangeType *ChangeType `json:"changetype,omitempty"`
	Records    []Record    `json:"records"`
	Comments   []Comment   `json:"comments,omitempty"`
}

RRset structure with JSON API metadata

type RRsets

type RRsets struct {
	Sets []RRset `json:"rrsets,omitempty"`
}

RRsets structure with JSON API metadata

type Record

type Record struct {
	Content  *string `json:"content,omitempty"`
	Disabled *bool   `json:"disabled,omitempty"`
	SetPTR   *bool   `json:"set-ptr,omitempty"`
}

Record structure with JSON API metadata

type RecordsService

type RecordsService service

RecordsService handles communication with the records related methods of the Client API

func (*RecordsService) Add

func (r *RecordsService) Add(ctx context.Context, domain string, name string, recordType RRType, ttl uint32, content []string, options ...func(*RRset)) error

Add creates a new resource record

Example (Basic)
pdns := powerdns.NewClient("http://localhost:8080", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)
ctx := context.Background()

if err := pdns.Records.Add(ctx, "example.com.", "www.example.com.", powerdns.RRTypeA, 1337, []string{"127.0.0.9"}); err != nil {
	log.Fatalf("%v", err)
}
Output:

Example (MX)
pdns := powerdns.NewClient("http://localhost:8080", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)
ctx := context.Background()

if err := pdns.Records.Add(ctx, "example.com.", "www.example.com.", powerdns.RRTypeMX, 1337, []string{"10 mx1.example.com.", "20 mx2.example.com."}); err != nil {
	log.Fatalf("%v", err)
}
Output:

Example (TXT)
pdns := powerdns.NewClient("http://localhost:8080", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)
ctx := context.Background()

if err := pdns.Records.Add(ctx, "example.com.", "www.example.com.", powerdns.RRTypeTXT, 1337, []string{"\"foo1\""}); err != nil {
	log.Fatalf("%v", err)
}
Output:

func (*RecordsService) Change

func (r *RecordsService) Change(ctx context.Context, domain string, name string, recordType RRType, ttl uint32, content []string, options ...func(*RRset)) error

Change replaces an existing resource record

Example
pdns := powerdns.NewClient("http://localhost:8080", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)
ctx := context.Background()

if err := pdns.Records.Change(ctx, "example.com.", "www.example.com.", powerdns.RRTypeA, 42, []string{"127.0.0.10"}); err != nil {
	log.Fatalf("%v", err)
}
Output:

func (*RecordsService) Delete

func (r *RecordsService) Delete(ctx context.Context, domain string, name string, recordType RRType) error

Delete removes an existing resource record

func (*RecordsService) Get added in v3.6.0

func (r *RecordsService) Get(ctx context.Context, domain, name string, recordType *RRType) ([]RRset, error)

Get retrieves rrsets with name and recordType (if provided)

func (*RecordsService) Patch

func (r *RecordsService) Patch(ctx context.Context, domain string, rrSets *RRsets) error

Patch method makes patch of already prepared rrsets

type Server

type Server struct {
	Type       *string `json:"type,omitempty"`
	ID         *string `json:"id,omitempty"`
	DaemonType *string `json:"daemon_type,omitempty"`
	Version    *string `json:"version,omitempty"`
	URL        *string `json:"url,omitempty"`
	ConfigURL  *string `json:"config_url,omitempty"`
	ZonesURL   *string `json:"zones_url,omitempty"`
}

Server structure with JSON API metadata

type ServersService

type ServersService service

ServersService handles communication with the servers related methods of the Client API

func (*ServersService) CacheFlush

func (s *ServersService) CacheFlush(ctx context.Context, vHost string, domain string) (*CacheFlushResult, error)

CacheFlush flushes a cache-entry by name

func (*ServersService) Get

func (s *ServersService) Get(ctx context.Context, vHost string) (*Server, error)

Get returns a certain Server

func (*ServersService) List

func (s *ServersService) List(ctx context.Context) ([]Server, error)

List retrieves a list of Servers

type Statistic

type Statistic struct {
	Name *string `json:"name,omitempty"`
	Type *string `json:"type,omitempty"`

	// Contrary to the authoritative API specification, the "size" field has actually been implemented as string instead of integer.
	Size *string `json:"size,omitempty"`

	// The "value" field contains either a string or a list of objects, depending on the "type".
	Value interface{} `json:"value,omitempty"`
}

Statistic structure with JSON API metadata

type StatisticsService

type StatisticsService service

StatisticsService handles communication with the statistics related methods of the Client API

func (*StatisticsService) Get

func (s *StatisticsService) Get(ctx context.Context, statisticName string) ([]Statistic, error)

Get retrieves certain Statistics

func (*StatisticsService) List

func (s *StatisticsService) List(ctx context.Context) ([]Statistic, error)

List retrieves a list of Statistics

type TSIGKey added in v3.8.0

type TSIGKey struct {
	Name      *string `json:"name,omitempty"`
	ID        *string `json:"id,omitempty"`
	Algorithm *string `json:"algorithm,omitempty"`
	Key       *string `json:"key,omitempty"`
	Type      *string `json:"type,omitempty"`
}

TSIGKey structure with JSON API metadata

type TSIGKeyService added in v3.8.0

type TSIGKeyService service

TSIGKeyService handles communication with the tsigs related methods of the Client API

func (*TSIGKeyService) Change added in v3.8.0

func (t *TSIGKeyService) Change(ctx context.Context, id string, newKey TSIGKey) (*TSIGKey, error)
Example
pdns := powerdns.NewClient("http://localhost:8080", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)
ctx := context.Background()

if _, err := pdns.TSIGKey.Change(ctx, *exampleTSIGKey.ID, exampleTSIGKey); err != nil {
	log.Fatalf("%v", err)
}
Output:

func (*TSIGKeyService) Create added in v3.8.0

func (t *TSIGKeyService) Create(ctx context.Context, name, algorithm, key string) (*TSIGKey, error)

Create a new TSIG Key setting empty string for key will generate it

Example
pdns := powerdns.NewClient("http://localhost:8080", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)
ctx := context.Background()

_, err := pdns.TSIGKey.Create(ctx, *exampleTSIGKey.Name, *exampleTSIGKey.Algorithm, "")
if err != nil {
	log.Fatalf("%v", err)
}
Output:

func (*TSIGKeyService) Delete added in v3.8.0

func (t *TSIGKeyService) Delete(ctx context.Context, id string) error
Example
pdns := powerdns.NewClient("http://localhost:8080", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)
ctx := context.Background()

if err := pdns.TSIGKey.Delete(ctx, *exampleTSIGKey.ID); err != nil {
	log.Fatalf("%v", err)
}
Output:

func (*TSIGKeyService) Get added in v3.8.0

func (t *TSIGKeyService) Get(ctx context.Context, id string) (*TSIGKey, error)

Get returns a certain TSIGKeys

Example
pdns := powerdns.NewClient("http://localhost:8080", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)
ctx := context.Background()

if _, err := pdns.TSIGKey.Get(ctx, *exampleTSIGKey.ID); err != nil {
	log.Fatalf("%v", err)
}
Output:

func (*TSIGKeyService) List added in v3.8.0

func (t *TSIGKeyService) List(ctx context.Context) ([]TSIGKey, error)

List retrieves a list of TSIGKeys

Example
pdns := powerdns.NewClient("http://localhost:8080", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)
ctx := context.Background()

if _, err := pdns.TSIGKey.List(ctx); err != nil {
	log.Fatalf("%v", err)
}
Output:

type Zone

type Zone struct {
	ID               *string   `json:"id,omitempty"`
	Name             *string   `json:"name,omitempty"`
	Type             *ZoneType `json:"type,omitempty"`
	URL              *string   `json:"url,omitempty"`
	Kind             *ZoneKind `json:"kind,omitempty"`
	RRsets           []RRset   `json:"rrsets,omitempty"`
	Serial           *uint32   `json:"serial,omitempty"`
	NotifiedSerial   *uint32   `json:"notified_serial,omitempty"`
	EditedSerial     *uint32   `json:"edited_serial,omitempty"`
	Masters          []string  `json:"masters,omitempty"`
	DNSsec           *bool     `json:"dnssec,omitempty"`
	Nsec3Param       *string   `json:"nsec3param,omitempty"`
	Nsec3Narrow      *bool     `json:"nsec3narrow,omitempty"`
	Presigned        *bool     `json:"presigned,omitempty"`
	SOAEdit          *string   `json:"soa_edit,omitempty"`
	SOAEditAPI       *string   `json:"soa_edit_api,omitempty"`
	APIRectify       *bool     `json:"api_rectify,omitempty"`
	Zone             *string   `json:"zone,omitempty"`
	Catalog          *string   `json:"catalog,omitempty"`
	Account          *string   `json:"account,omitempty"`
	Nameservers      []string  `json:"nameservers,omitempty"`
	MasterTSIGKeyIDs []string  `json:"master_tsig_key_ids,omitempty"`
	SlaveTSIGKeyIDs  []string  `json:"slave_tsig_key_ids,omitempty"`
}

Zone structure with JSON API metadata

type ZoneKind

type ZoneKind string

ZoneKind string type

const (
	// NativeZoneKind sets the zone's kind to native
	NativeZoneKind ZoneKind = "Native"
	// MasterZoneKind sets the zone's kind to master
	MasterZoneKind ZoneKind = "Master"
	// SlaveZoneKind sets the zone's kind to slave
	SlaveZoneKind ZoneKind = "Slave"
	// ProducerZoneKind sets the zone's kind to producer
	ProducerZoneKind ZoneKind = "Producer"
	// ConsumerZoneKind sets the zone's kind to consumer
	ConsumerZoneKind ZoneKind = "Consumer"
)

func ZoneKindPtr

func ZoneKindPtr(v ZoneKind) *ZoneKind

ZoneKindPtr is a helper function that allocates a new ZoneKind value to store v and returns a pointer to it.

type ZoneType

type ZoneType string

ZoneType string type

const ZoneZoneType ZoneType = "Zone"

ZoneZoneType sets the zone's type to zone

func ZoneTypePtr

func ZoneTypePtr(v ZoneType) *ZoneType

ZoneTypePtr is a helper function that allocates a new ZoneType value to store v and returns a pointer to it.

type ZonesService

type ZonesService service

ZonesService handles communication with the zones related methods of the Client API

func (*ZonesService) Add

func (z *ZonesService) Add(ctx context.Context, zone *Zone) (*Zone, error)

Add pre-created zone

func (*ZonesService) AddMaster

func (z *ZonesService) AddMaster(ctx context.Context, domain string, dnssec bool, nsec3Param string, nsec3Narrow bool, soaEdit, soaEditApi string, apiRectify bool, nameservers []string) (*Zone, error)

AddMaster creates a new master zone

func (*ZonesService) AddNative

func (z *ZonesService) AddNative(ctx context.Context, domain string, dnssec bool, nsec3Param string, nsec3Narrow bool, soaEdit, soaEditApi string, apiRectify bool, nameservers []string) (*Zone, error)

AddNative creates a new native zone

Example
pdns := powerdns.NewClient("http://localhost:8080", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)
ctx := context.Background()

zone, err := pdns.Zones.AddNative(ctx, "example.com.", false, "", false, "", "", true, []string{"localhost."})
if err != nil {
	log.Fatalf("%v", err)
}

log.Printf("Zone: %v", zone)
Output:

func (*ZonesService) AddSlave

func (z *ZonesService) AddSlave(ctx context.Context, domain string, masters []string) (*Zone, error)

AddSlave creates a new slave zone

func (*ZonesService) AxfrRetrieve added in v3.3.0

func (z *ZonesService) AxfrRetrieve(ctx context.Context, domain string) (*AxfrRetrieveResult, error)

AxfrRetrieve requests a axfr transfer from the master to requesting slave

func (*ZonesService) Change

func (z *ZonesService) Change(ctx context.Context, domain string, zone *Zone) error

Change modifies an existing zone

Example
pdns := powerdns.NewClient("http://localhost:8080", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)
ctx := context.Background()
zoneChangeSet := &powerdns.Zone{
	Account: powerdns.String("test"),
	DNSsec:  powerdns.Bool(true),
}

if err := pdns.Zones.Change(ctx, "example.com.", zoneChangeSet); err != nil {
	log.Fatalf("%v", err)
}
Output:

func (*ZonesService) Delete

func (z *ZonesService) Delete(ctx context.Context, domain string) error

Delete removes a certain Zone for a given domain

func (*ZonesService) Export

func (z *ZonesService) Export(ctx context.Context, domain string) (Export, error)

Export returns a BIND-like Zone file

func (*ZonesService) Get

func (z *ZonesService) Get(ctx context.Context, domain string) (*Zone, error)

Get returns a certain Zone for a given domain

Example
pdns := powerdns.NewClient("http://localhost:8080", "localhost", map[string]string{"X-API-Key": "apipw"}, nil)
ctx := context.Background()

zone, err := pdns.Zones.Get(ctx, "example.com.")
if err != nil {
	log.Fatalf("%v", err)
}

log.Printf("Zone: %v", zone)
Output:

func (*ZonesService) List

func (z *ZonesService) List(ctx context.Context) ([]Zone, error)

List retrieves a list of Zones

func (*ZonesService) Notify

func (z *ZonesService) Notify(ctx context.Context, domain string) (*NotifyResult, error)

Notify sends a DNS notify packet to all slaves

Jump to

Keyboard shortcuts

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