powerdns

package module
v0.0.0-...-4e299eb Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2019 License: MIT Imports: 7 Imported by: 0

README

PowerDNS 4.1 API bindings for Golang

This community project provides bindings for the currently latest version of PowerDNS.

Build Status Go Report Card

Setup

Requirements
  • PowerDNS 4.1 ("API v1")
    • --webserver=yes --api=yes --api-key=apipw --api-readonly=no
    • Note that API v1 is actively maintained. There are differences between 3.x, 4.0 and 4.1 and this client works only with 4.1.
  • Go 1.10/1.11 (should work with other minor releases as well)
Install from source
go get -u github.com/joeig/go-powerdns

Usage

Initialize the handle
import "github.com/joeig/go-powerdns"

headers := make(map[string]string)
headers["X-API-Key"] = "apipw"
pdns := powerdns.NewClient("http://localhost:80", "localhost", headers, 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.

Request zone data
zones, err := pdns.GetZones()
zone, err := pdns.GetZone("example.com")
export, err := zone.Export()
Add/change/delete resource records
err := zone.AddRecord("www.example.com", "AAAA", 60, []string{"::1"})
err := zone.ChangeRecord("www.example.com", "AAAA", 3600, []string{"::1"})
err := zone.DeleteRecord("www.example.com", "A")
notifyResult, err := zone.Notify()
Request server information and statistics
statistics, err := pdns.GetStatistics()
servers, err := pdns.GetServers()
server, err := pdns.GetServer()
Handle DNSSEC cryptographic material
cryptokeys, err := zone.GetCryptokeys()
cryptokey, err := zone.GetCryptokey("1337")
err := cryptokey.ToggleCryptokey()
err := cryptokey.DeleteCryptokey()

Documentation

See GoDoc.

Contribution

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

Start a PowerDNS authoritative server including a generic MySQL backend, DNSSEC support and some fixtures using Docker compose:

docker-compose up
docker-compose exec powerdns sh init_docker_fixtures.sh

Based on the work of jgreat and waynz0r.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	Content    string `json:"content"`
	Account    string `json:"account"`
	ModifiedAt int    `json:"modified_at"`
}

Comment structure with JSON API metadata

type Cryptokey

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

Cryptokey structure with JSON API metadata

func (*Cryptokey) DeleteCryptokey

func (c *Cryptokey) DeleteCryptokey() error

DeleteCryptokey removes a given Cryptokey

func (*Cryptokey) ToggleCryptokey

func (c *Cryptokey) ToggleCryptokey() error

ToggleCryptokey enables/disables a given Cryptokey

type Error

type Error struct {
	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"`
}

NotifyResult structure with JSON API metadata

type PowerDNS

type PowerDNS struct {
	Scheme   string
	Hostname string
	Port     string
	VHost    string
	Headers  map[string]string
	// contains filtered or unexported fields
}

PowerDNS configuration structure

func NewClient

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

NewClient initializes a new PowerDNS client configuration

func (*PowerDNS) GetServer

func (p *PowerDNS) GetServer() (*Server, error)

GetServer returns a certain Server

func (*PowerDNS) GetServers

func (p *PowerDNS) GetServers() ([]Server, error)

GetServers retrieves a list of Servers

func (*PowerDNS) GetStatistics

func (p *PowerDNS) GetStatistics() ([]Statistic, error)

GetStatistics retrieves a list of Statistics

func (*PowerDNS) GetZone

func (p *PowerDNS) GetZone(domain string) (*Zone, error)

GetZone returns a certain Zone for a given domain

func (*PowerDNS) GetZones

func (p *PowerDNS) GetZones() ([]Zone, error)

GetZones retrieves a list of Zones

type RRset

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

RRset structure with JSON API metadata

type RRsets

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

RRsets structure with JSON API metadata

type Record

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

Record structure with JSON API metadata

type Server

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

Server structure with JSON API metadata

type Statistic

type Statistic struct {
	Name  string `json:"name"`
	Type  string `json:"type"`
	Value string `json:"value"`
}

Statistic structure with JSON API metadata

type Zone

type Zone struct {
	ID             string   `json:"id"`
	Name           string   `json:"name"`
	Type           string   `json:"type"`
	URL            string   `json:"url"`
	Kind           string   `json:"kind"`
	RRsets         []RRset  `json:"rrsets"`
	Serial         int      `json:"serial"`
	NotifiedSerial int      `json:"notified_serial"`
	Masters        []string `json:"masters"`
	DNSsec         bool     `json:"dnssec"`
	Nsec3Param     string   `json:"nsec3param"`
	Nsec3Narrow    bool     `json:"nsec3narrow"`
	Presigned      bool     `json:"presigned"`
	SOAEdit        string   `json:"soa_edit"`
	SOAEditAPI     string   `json:"soa_edit_api"`
	APIRectify     bool     `json:"api_rectify"`
	Zone           string   `json:"zone"`
	Account        string   `json:"account"`
	Nameservers    []string `json:"nameservers"`
	PowerDNSHandle *PowerDNS
}

Zone structure with JSON API metadata

func (*Zone) AddRecord

func (z *Zone) AddRecord(name string, recordType string, ttl int, content []string) error

AddRecord creates a new resource record

func (*Zone) ChangeRecord

func (z *Zone) ChangeRecord(name string, recordType string, ttl int, content []string) error

ChangeRecord replaces an existing resource record

func (*Zone) DeleteRecord

func (z *Zone) DeleteRecord(name string, recordType string) error

DeleteRecord removes an existing resource record

func (*Zone) Export

func (z *Zone) Export() (Export, error)

Export returns a BIND-like Zone file

func (*Zone) GetCryptokey

func (z *Zone) GetCryptokey(id string) (*Cryptokey, error)

GetCryptokey returns a certain Cryptokey instance of a given Zone

func (*Zone) GetCryptokeys

func (z *Zone) GetCryptokeys() ([]Cryptokey, error)

GetCryptokeys retrieves a list of Cryptokeys that belong to a Zone

func (*Zone) Notify

func (z *Zone) Notify() (*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