powerdns

package module
v2.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2019 License: MIT Imports: 10 Imported by: 13

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 Coverage Status Documentation

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.
  • Tested with Go version 1.11/1.12/1.13, according to Go's version support policy (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"

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
zones, err := pdns.Zones.List()
zone, err := pdns.Zones.Get("example.com")
export, err := pdns.Zones.Export("example.com")
zone, err := pdns.Zones.AddNative("example.com", true, "", false, "foo", "foo", true, []string{"ns.foo.tld."})
err := pdns.Zones.Change("example.com", &zone)
err := pdns.Zones.Delete("example.com")
Add/change/delete resource records
err := pdns.Records.Add("example.com", "www.example.com", "AAAA", 60, []string{"::1"})
err := pdns.Records.Change("example.com", "www.example.com", "AAAA", 3600, []string{"::1"})
err := pdns.Records.Delete("example.com", "www.example.com", "A")
notifyResult, err := pdns.Records.Notify("example.com")
Request server information and statistics
statistics, err := pdns.Statistics.List()
servers, err := pdns.Servers.List()
server, err := pdns.Servers.Get("localhost")
Handle DNSSEC cryptographic material
cryptokeys, err := pdns.Cryptokeys.List()
cryptokey, err := pdns.Cryptokeys.Get("example.com", "1337")
err := pdns.Cryptokeys.Delete("example.com", "1337")

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

It's also possible to target mocks against this server:

make test-without-mocks

Based on the work of jgreat and waynz0r.

Documentation

Index

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.

Types

type Client

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

	Cryptokeys *CryptokeysService
	Records    *RecordsService
	Servers    *ServersService
	Statistics *StatisticsService
	Zones      *ZonesService
	// 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

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 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(domain string, id uint64) error

Delete removes a given Cryptokey

func (*CryptokeysService) Get

func (c *CryptokeysService) Get(domain string, id uint64) (*Cryptokey, error)

Get returns a certain Cryptokey instance of a given Zone

func (*CryptokeysService) List

func (c *CryptokeysService) List(domain string) ([]Cryptokey, error)

List retrieves a list of Cryptokeys that belong to a Zone

type Error

type Error struct {
	Status  string
	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 RRset

type RRset struct {
	Name       *string   `json:"name,omitempty"`
	Type       *string   `json:"type,omitempty"`
	TTL        *uint32   `json:"ttl,omitempty"`
	ChangeType *string   `json:"changetype,omitempty"`
	Records    []Record  `json:"records,omitempty"`
	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(domain string, name string, recordType string, ttl uint32, content []string) error

Add creates a new resource record

func (*RecordsService) Change

func (r *RecordsService) Change(domain string, name string, recordType string, ttl uint32, content []string) error

Change replaces an existing resource record

func (*RecordsService) Delete

func (r *RecordsService) Delete(domain string, name string, recordType string) error

Delete removes an existing resource record

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

func (s *ServersService) Get(vHost string) (*Server, error)

Get returns a certain Server

func (*ServersService) List

func (s *ServersService) List() ([]Server, error)

List retrieves a list of Servers

type Statistic

type Statistic struct {
	Name  *string `json:"name,omitempty"`
	Type  *string `json:"type,omitempty"`
	Value *string `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) List

func (s *StatisticsService) List() ([]Statistic, error)

List retrieves a list of Statistics

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"`
	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"`
	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"
)

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

func (z *ZonesService) AddMaster(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(domain string, dnssec bool, nsec3Param string, nsec3Narrow bool, soaEdit, soaEditApi string, apiRectify bool, nameservers []string) (*Zone, error)

AddNative creates a new native zone

func (*ZonesService) AddSlave

func (z *ZonesService) AddSlave(domain string, masters []string) (*Zone, error)

AddSlave creates a new slave zone

func (*ZonesService) Change

func (z *ZonesService) Change(domain string, zone *Zone) error

Change modifies an existing zone

func (*ZonesService) Delete

func (z *ZonesService) Delete(domain string) error

Delete removes a certain Zone for a given domain

func (*ZonesService) Export

func (z *ZonesService) Export(domain string) (Export, error)

Export returns a BIND-like Zone file

func (*ZonesService) Get

func (z *ZonesService) Get(domain string) (*Zone, error)

Get returns a certain Zone for a given domain

func (*ZonesService) List

func (z *ZonesService) List() ([]Zone, error)

List retrieves a list of Zones

func (*ZonesService) Notify

func (z *ZonesService) Notify(domain string) (*NotifyResult, error)

Notify sends a DNS notify packet to all slaves

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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