gandi

package module
v0.0.0-...-77cf002 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2020 License: MIT Imports: 7 Imported by: 1

README

Gandi LiveDNS Go library

GoDoc License

As of january 2020, this library will no longer be maintained, it is superseded by https://github.com/tiramiseb/go-gandi. Don't hesitate to make PRs bugfixes or security fixes though...

This library interacts with Gandi's LiveDNS API, to manage domains hosted on Gandi. This API returns some data as HTTP headers, please note those are ignored by this library.

A simple CLI is also shipped with this library. It returns responses to the requests in JSON.

Example

This example mimics the steps of the official LiveDNS documentation example.

First (step 1), get your API key from the "Security" section in new Account admin panel to be able to make authenticated requests to the API. Note: sharing_id is optional. It is used e.g. when the API key is registered to a user, where the domain you want to manage is not registered with that user (but the user does have rights on that zone/organization).

import "github.com/tiramiseb/go-gandi-livedns"
apikey := "<the API key>"
sharing_id := "<the sharing_id for that domain, may be nil>"
g := gandi.New(apikey, sharing_id)
// Step 2: create the zone
zone := g.CreateZone("example.com Zone")
// Step 3: create DNS records
g.CreateZoneRecord(zone.UUID, "www", "A", 3600, []string{"192.168.0.1"})
// Step 4: associate the domain
g.AttachDomainToZone(zone.UUID, "example.com")
// Step 5: change nameservers
nameservers := g.getDomainNS("example.com")
// Step 6: setup automatic DNSSEC signing
g.SignDomain("example.com")
// Getting the key href
g.GetDomainKeys("example.com")
// Deleting the key
g.DeleteDomainKey("example.com", "bb004a38-566b-4200-bd6e-830b48ea50cf")
// Recovering the key
g.UpdateDomainKey("example.com", "bb004a38-566b-4200-bd6e-830b48ea50cf", false)
// Step 7: adding extra security with a slave server
// Creating a TSIG key
tsig, _ := g.CreateTsig()
// Adding the TSIG key for AXFRs
g.AddTsigToDomain("example.com", tsig.UUID)
// Adding two slaves servers to the domain
for _, host := range []string{"198.51.100.1", "2001:DB8::1"} {
    g.AddSlaveToDomain("example.com", host)
}
// Getting slave BIND sample configurations
g.GetTsigBIND("85e7b6e3-4553-479b-b968-cd0c77143802")

Compiling the CLI

cd cmd
go build -o gandi

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Domain

type Domain struct {
	FQDN              string `json:"fqdn,omitempty"`
	DomainHref        string `json:"domain_href,omitempty"`
	DomainKeysHref    string `json:"domain_keys_href,omitempty"`
	DomainRecordsHref string `json:"domain_records_href,omitempty"`
	ZoneUUID          string `json:"zone_uuid,omitempty"`
	ZoneHref          string `json:"zone_href,omitempty"`
	ZoneRecordsHref   string `json:"zone_records_href,omitempty"`
}

Domain represents a DNS domain

type Gandi

type Gandi struct {
	// contains filtered or unexported fields
}

Gandi makes it easier to interact with Gandi LiveDNS

func New

func New(apikey string, sharing_id string) *Gandi

New instantiates a new Gandi instance

func (*Gandi) AddDomainToZone

func (g *Gandi) AddDomainToZone(fqdn, uuid string) (response StandardResponse, err error)

AddDomainToZone adds a domain to a zone It is equivalent to AttachDomainToZone, the only difference is the entry point in the LiveDNS API.

func (*Gandi) AddSlaveToDomain

func (g *Gandi) AddSlaveToDomain(fqdn, host string) (err error)

AddSlaveToDomain adds a slave to a domain

func (*Gandi) AddTsigToDomain

func (g *Gandi) AddTsigToDomain(fqdn, uuid string) (err error)

AddTsigToDomain adds a tsig to a domain

func (*Gandi) AttachDomainToZone

func (g *Gandi) AttachDomainToZone(uuid, fqdn string) (response StandardResponse, err error)

AttachDomainToZone attaches a domain to a zone

func (*Gandi) ChangeAssociatedZone

func (g *Gandi) ChangeAssociatedZone(fqdn, uuid string) (response StandardResponse, err error)

ChangeAssociatedZone changes the zone associated to a domain

func (*Gandi) ChangeDomainRecordWithNameAndType

func (g *Gandi) ChangeDomainRecordWithNameAndType(fqdn, name, recordtype string, ttl int, values []string) (response StandardResponse, err error)

ChangeDomainRecordWithNameAndType changes the record with the given name and the given type in the zone attached to a domain

func (*Gandi) ChangeDomainRecords

func (g *Gandi) ChangeDomainRecords(fqdn string, records []ZoneRecord) (response StandardResponse, err error)

ChangeDomainRecords changes all records in the zone attached to a domain

func (*Gandi) ChangeDomainRecordsWithName

func (g *Gandi) ChangeDomainRecordsWithName(fqdn, name string, records []ZoneRecord) (response StandardResponse, err error)

ChangeDomainRecordsWithName changes all records with the given name in the zone attached to the domain

func (*Gandi) ChangeZoneRecordWithNameAndType

func (g *Gandi) ChangeZoneRecordWithNameAndType(uuid, name, recordtype string, ttl int, values []string) (response StandardResponse, err error)

ChangeZoneRecordWithNameAndType changes the zone record with the given name and the given type

func (*Gandi) ChangeZoneRecords

func (g *Gandi) ChangeZoneRecords(uuid string, records []ZoneRecord) (response StandardResponse, err error)

ChangeZoneRecords changes all records in a zone

func (*Gandi) ChangeZoneRecordsAsText

func (g *Gandi) ChangeZoneRecordsAsText(uuid string, records []byte) (response StandardResponse, err error)

ChangeZoneRecordsAsText changes all zone records, taking them as text ... and by text, I mean a slice of bytes

func (*Gandi) ChangeZoneRecordsWithName

func (g *Gandi) ChangeZoneRecordsWithName(uuid, name string, records []ZoneRecord) (response StandardResponse, err error)

ChangeZoneRecordsWithName changes all zone records with the given name

func (*Gandi) CreateDomainRecord

func (g *Gandi) CreateDomainRecord(fqdn, name, recordtype string, ttl int, values []string) (response StandardResponse, err error)

CreateDomainRecord creates a record in the zone attached to a domain

func (*Gandi) CreateSnapshot

func (g *Gandi) CreateSnapshot(uuid string) (response StandardResponse, err error)

CreateSnapshot creates a zone

func (*Gandi) CreateTsig

func (g *Gandi) CreateTsig() (tsig Tsig, err error)

CreateTsig creates a tsig

func (*Gandi) CreateZone

func (g *Gandi) CreateZone(name string) (response StandardResponse, err error)

CreateZone creates a zone

func (*Gandi) CreateZoneRecord

func (g *Gandi) CreateZoneRecord(uuid, name, recordtype string, ttl int, values []string) (response StandardResponse, err error)

CreateZoneRecord creates a record in a zone

func (*Gandi) DelSlaveFromDomain

func (g *Gandi) DelSlaveFromDomain(fqdn, host string) (err error)

DelSlaveFromDomain removes a slave from a domain

func (*Gandi) DeleteAllDomainRecords

func (g *Gandi) DeleteAllDomainRecords(fqdn string) (err error)

DeleteAllDomainRecords deletes all records in the zone attached to a domain

func (*Gandi) DeleteAllZoneRecords

func (g *Gandi) DeleteAllZoneRecords(uuid string) (err error)

DeleteAllZoneRecords deletes all records in a zone

func (*Gandi) DeleteDomainKey

func (g *Gandi) DeleteDomainKey(fqdn, uuid string) (err error)

DeleteDomainKey deletes a signing key from a domain

func (*Gandi) DeleteDomainRecord

func (g *Gandi) DeleteDomainRecord(fqdn, name, recordtype string) (err error)

DeleteDomainRecord deletes the record with the given name and the given type in the zone attached to a domain

func (*Gandi) DeleteDomainRecords

func (g *Gandi) DeleteDomainRecords(fqdn, name string) (err error)

DeleteDomainRecords deletes all records with the given name in the zone attached to a domain

func (*Gandi) DeleteZone

func (g *Gandi) DeleteZone(uuid string) (err error)

DeleteZone deletes a zone

func (*Gandi) DeleteZoneRecord

func (g *Gandi) DeleteZoneRecord(uuid, name, recordtype string) (err error)

DeleteZoneRecord deletes the record with the given name and the given type in a zone

func (*Gandi) DeleteZoneRecords

func (g *Gandi) DeleteZoneRecords(uuid, name string) (err error)

DeleteZoneRecords deletes all records with the given name in a zone

func (*Gandi) DetachDomain

func (g *Gandi) DetachDomain(fqdn string) (err error)

DetachDomain detaches a domain from the zone it is attached to

func (*Gandi) GetDomain

func (g *Gandi) GetDomain(fqdn string) (domain Domain, err error)

GetDomain returns a domain

func (*Gandi) GetDomainKeys

func (g *Gandi) GetDomainKeys(fqdn string) (keys []SigningKey, err error)

GetDomainKeys returns data about the signing keys created for a domain

func (*Gandi) GetDomainNS

func (g *Gandi) GetDomainNS(fqdn string) (ns []string, err error)

GetDomainNS returns the list of the nameservers for a domain

func (*Gandi) GetDomainRecordWithNameAndType

func (g *Gandi) GetDomainRecordWithNameAndType(fqdn, name, recordtype string) (record ZoneRecord, err error)

GetDomainRecordWithNameAndType gets the record with specific name and type in the zone attached to the domain

func (*Gandi) GetSnapshot

func (g *Gandi) GetSnapshot(uuid, snapUUID string) (snapshot Snapshot, err error)

GetSnapshot returns a zone

func (*Gandi) GetTsig

func (g *Gandi) GetTsig(uuid string) (tsig Tsig, err error)

GetTsig lists more tsig details

func (*Gandi) GetTsigBIND

func (g *Gandi) GetTsigBIND(uuid string) ([]byte, error)

GetTsigBIND shows a BIND nameserver config, and includes the nameservers available for zone transfers

func (*Gandi) GetTsigKnot

func (g *Gandi) GetTsigKnot(uuid string) ([]byte, error)

GetTsigKnot shows a Knot nameserver config, and includes the nameservers available for zone transfers

func (*Gandi) GetTsigNSD

func (g *Gandi) GetTsigNSD(uuid string) ([]byte, error)

GetTsigNSD shows a NSD nameserver config, and includes the nameservers available for zone transfers

func (*Gandi) GetTsigPowerDNS

func (g *Gandi) GetTsigPowerDNS(uuid string) ([]byte, error)

GetTsigPowerDNS shows a PowerDNS nameserver config, and includes the nameservers available for zone transfers

func (*Gandi) GetZone

func (g *Gandi) GetZone(uuid string) (zone Zone, err error)

GetZone returns a zone

func (*Gandi) GetZoneDomains

func (g *Gandi) GetZoneDomains(uuid string) (domains []Domain, err error)

GetZoneDomains returns domains attached to a zone

func (*Gandi) GetZoneRecordWithNameAndType

func (g *Gandi) GetZoneRecordWithNameAndType(uuid, name, recordtype string) (record ZoneRecord, err error)

GetZoneRecordWithNameAndType gets the record with specific name and type in a zone

func (*Gandi) ListDomainRecords

func (g *Gandi) ListDomainRecords(fqdn string) (records []ZoneRecord, err error)

ListDomainRecords lists all records in the zone associated with a domain

func (*Gandi) ListDomainRecordsWithName

func (g *Gandi) ListDomainRecordsWithName(fqdn, name string) (records []ZoneRecord, err error)

ListDomainRecordsWithName lists all records with a specific name in a zone

func (*Gandi) ListDomains

func (g *Gandi) ListDomains() (domains []Domain, err error)

ListDomains lists all domains

func (*Gandi) ListSlavesInDomain

func (g *Gandi) ListSlavesInDomain(fqdn string) (slaves []string, err error)

ListSlavesInDomain lists slaves in a domain

func (*Gandi) ListSnapshots

func (g *Gandi) ListSnapshots(uuid string) (snapshots []Snapshot, err error)

ListSnapshots lists all zones

func (*Gandi) ListTsigs

func (g *Gandi) ListTsigs() (tsigs []Tsig, err error)

ListTsigs lists all tsigs

func (*Gandi) ListZoneRecords

func (g *Gandi) ListZoneRecords(uuid string) (records []ZoneRecord, err error)

ListZoneRecords lists all records in a zone

func (*Gandi) ListZoneRecordsAsText

func (g *Gandi) ListZoneRecordsAsText(uuid string) ([]byte, error)

ListZoneRecordsAsText lists all records in a zone and returns them as a text file ... and by text, I mean a slice of bytes

func (*Gandi) ListZoneRecordsWithName

func (g *Gandi) ListZoneRecordsWithName(uuid, name string) (records []ZoneRecord, err error)

ListZoneRecordsWithName lists all records with a specific name in a zone

func (*Gandi) ListZones

func (g *Gandi) ListZones() (zones []Zone, err error)

ListZones lists all zones

func (*Gandi) SignDomain

func (g *Gandi) SignDomain(fqdn string) (response StandardResponse, err error)

SignDomain creates a DNSKEY and asks Gandi servers to automatically sign the domain

func (*Gandi) UpdateDomainKey

func (g *Gandi) UpdateDomainKey(fqdn, uuid string, deleted bool) (err error)

UpdateDomainKey updates a signing key for a domain (only the deleted status, actually...)

func (*Gandi) UpdateZone

func (g *Gandi) UpdateZone(uuid, name string) (response StandardResponse, err error)

UpdateZone updates a zone (only its name, actually...)

type SigningKey

type SigningKey struct {
	Status        string `json:"status,omitempty"`
	UUID          string `json:"uuid,omitempty"`
	Algorithm     int    `json:"algorithm,omitempty"`
	Deleted       *bool  `json:"deleted"`
	AlgorithmName string `json:"algorithm_name,omitempty"`
	FQDN          string `json:"fqdn,omitempty"`
	Flags         int    `json:"flags,omitempty"`
	DS            string `json:"ds,omitempty"`
	KeyHref       string `json:"key_href,omitempty"`
}

SigningKey holds data about a DNSSEC signing key

type Snapshot

type Snapshot struct {
	UUID        string       `json:"uuid,omitempty"`
	DateCreated string       `json:"date_created,omitempty"`
	ZoneUUID    string       `json:"zone_uuid,omitempty"`
	ZoneData    []ZoneRecord `json:"zone_data,omitempty"`
}

Snapshot represents a zone snapshot

type StandardError

type StandardError struct {
	Location    string `json:"location"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

StandardError is embedded in a standard error

type StandardResponse

type StandardResponse struct {
	Code    int             `json:"code,omitempty"`
	Message string          `json:"message,omitempty"`
	UUID    string          `json:"uuid,omitempty"`
	Object  string          `json:"object,omitempty"`
	Cause   string          `json:"cause,omitempty"`
	Status  string          `json:"status,omitempty"`
	Errors  []StandardError `json:"errors,omitempty"`
}

StandardResponse is a standard response

type Tsig

type Tsig struct {
	KeyName       string      `json:"key_name, omitempty"`
	Secret        string      `json:"secret,omitempty"`
	UUID          string      `json:"uuid,omitempty"`
	AxfrTsigURL   string      `json:"axfr_tsig_url,omitempty"`
	ConfigSamples interface{} `json:"config_samples,omitempty"`
}

Tsig contains tsig data (no kidding!)

type Zone

type Zone struct {
	Retry           int    `json:"retry,omitempty"`
	UUID            string `json:"uuid,omitempty"`
	ZoneHref        string `json:"zone_href,omitempty"`
	Minimum         int    `json:"minimum,omitempty"`
	DomainsHref     string `json:"domains_href,omitempty"`
	Refresh         int    `json:"refresh,omitempty"`
	ZoneRecordsHref string `json:"zone_records_href,omitempty"`
	Expire          int    `json:"expire,omitempty"`
	SharingID       string `json:"sharing_id,omitempty"`
	Serial          int    `json:"serial,omitempty"`
	Email           string `json:"email,omitempty"`
	PrimaryNS       string `json:"primary_ns,omitempty"`
	Name            string `json:"name,omitempty"`
}

Zone represents a DNS Zone

type ZoneRecord

type ZoneRecord struct {
	RrsetType   string   `json:"rrset_type,omitempty"`
	RrsetTTL    int      `json:"rrset_ttl,omitempty"`
	RrsetName   string   `json:"rrset_name,omitempty"`
	RrsetHref   string   `json:"rrset_href,omitempty"`
	RrsetValues []string `json:"rrset_values,omitempty"`
}

ZoneRecord represents a DNS Record

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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