1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

GANDI_V5: Upgrade to newest github.com/tiramiseb/go-gandi

This commit is contained in:
Tom Limoncelli
2020-02-27 12:06:25 -05:00
committed by GitHub
parent 7c9a23b215
commit 1616c50ba7
9 changed files with 171 additions and 87 deletions

View File

@ -4,26 +4,11 @@ import "github.com/tiramiseb/go-gandi/internal/client"
// Domain represents a DNS 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"`
}
// SigningKey holds data about a DNSSEC signing key
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"`
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"`
AutomaticSnapshots *bool `json:"automatic_snapshots,omitempty"`
}
type zone struct {
@ -64,39 +49,26 @@ func (g *LiveDNS) UpdateDomain(fqdn string, details UpdateDomainRequest) (respon
return
}
// DetachDomain detaches a domain from the zone it is attached to
func (g *LiveDNS) DetachDomain(fqdn string) (err error) {
_, err = g.client.Delete("domains/"+fqdn, nil, nil)
// GetDomainAXFRSecondaries returns the list of IPs that are permitted to do AXFR transfers of the domain
func (g *LiveDNS) GetDomainAXFRSecondaries(fqdn string) (secondaries []string, err error) {
_, err = g.client.Get("domains/"+fqdn+"/axfr/slaves", nil, &secondaries)
return
}
// SignDomain creates a DNSKEY and asks Gandi servers to automatically sign the domain
func (g *LiveDNS) SignDomain(fqdn string) (response client.StandardResponse, err error) {
f := SigningKey{Flags: 257}
_, err = g.client.Post("domains/"+fqdn+"/keys", f, &response)
// CreateDomainAXFRSecondary adds an IP address to the list of IPs that are permitted to do AXFR transfers of the domain
func (g *LiveDNS) CreateDomainAXFRSecondary(fqdn string, ip string) (err error) {
_, err = g.client.Put("domains/"+fqdn+"/axfr/slaves/"+ip, nil, nil)
return
}
// GetDomainKeys returns data about the signing keys created for a domain
func (g *LiveDNS) GetDomainKeys(fqdn string) (keys []SigningKey, err error) {
_, err = g.client.Get("domains/"+fqdn+"/keys", nil, &keys)
return
}
// DeleteDomainKey deletes a signing key from a domain
func (g *LiveDNS) DeleteDomainKey(fqdn, uuid string) (err error) {
_, err = g.client.Delete("domains/"+fqdn+"/keys/"+uuid, nil, nil)
return
}
// UpdateDomainKey updates a signing key for a domain (only the deleted status, actually...)
func (g *LiveDNS) UpdateDomainKey(fqdn, uuid string, deleted bool) (err error) {
_, err = g.client.Put("domains/"+fqdn+"/keys/"+uuid, SigningKey{Deleted: &deleted}, nil)
// DeleteDomainAXFRSecondary removes an IP address from the list of IPs that are permitted to do AXFR transfers of the domain
func (g *LiveDNS) DeleteDomainAXFRSecondary(fqdn string, ip string) (response client.StandardResponse, err error) {
_, err = g.client.Delete("domains/"+fqdn+"/axfr/slaves/"+ip, nil, &response)
return
}
// GetDomainNS returns the list of the nameservers for a domain
func (g *LiveDNS) GetDomainNS(fqdn string) (ns []string, err error) {
_, err = g.client.Get("nameservers/"+fqdn, nil, &ns)
_, err = g.client.Get("domains/"+fqdn+"/nameservers", nil, &ns)
return
}

View File

@ -24,14 +24,14 @@ func (g *LiveDNS) ListDomainRecordsAsText(uuid string) ([]byte, error) {
return content, err
}
// ListDomainRecordsWithName lists all records with a specific name in a zone
func (g *LiveDNS) ListDomainRecordsWithName(fqdn, name string) (records []DomainRecord, err error) {
// ListDomainRecordsByName lists all records with a specific name in a zone
func (g *LiveDNS) ListDomainRecordsByName(fqdn, name string) (records []DomainRecord, err error) {
_, err = g.client.Get("domains/"+fqdn+"/records/"+name, nil, &records)
return
}
// GetDomainRecordWithNameAndType gets the record with specific name and type in the zone attached to the domain
func (g *LiveDNS) GetDomainRecordWithNameAndType(fqdn, name, recordtype string) (record DomainRecord, err error) {
// GetDomainRecordByNameAndType gets the record with specific name and type in the zone attached to the domain
func (g *LiveDNS) GetDomainRecordByNameAndType(fqdn, name, recordtype string) (record DomainRecord, err error) {
_, err = g.client.Get("domains/"+fqdn+"/records/"+name+"/"+recordtype, nil, &record)
return
}
@ -53,24 +53,25 @@ type itemsPrefixForZoneRecords struct {
Items []DomainRecord `json:"items"`
}
// ChangeDomainRecords changes all records in the zone attached to a domain
func (g *LiveDNS) ChangeDomainRecords(fqdn string, records []DomainRecord) (response client.StandardResponse, err error) {
// UpdateDomainRecords changes all records in the zone attached to a domain
func (g *LiveDNS) UpdateDomainRecords(fqdn string, records []DomainRecord) (response client.StandardResponse, err error) {
prefixedRecords := itemsPrefixForZoneRecords{Items: records}
_, err = g.client.Put("domains/"+fqdn+"/records", prefixedRecords, &response)
return
}
// ChangeDomainRecordsWithName changes all records with the given name in the zone attached to the domain
func (g *LiveDNS) ChangeDomainRecordsWithName(fqdn, name string, records []DomainRecord) (response client.StandardResponse, err error) {
// UpdateDomainRecordsByName changes all records with the given name in the zone attached to the domain
func (g *LiveDNS) UpdateDomainRecordsByName(fqdn, name string, records []DomainRecord) (response client.StandardResponse, err error) {
prefixedRecords := itemsPrefixForZoneRecords{Items: records}
_, err = g.client.Put("domains/"+fqdn+"/records/"+name, prefixedRecords, &response)
return
}
// ChangeDomainRecordWithNameAndType changes the record with the given name and the given type in the zone attached to a domain
func (g *LiveDNS) ChangeDomainRecordWithNameAndType(fqdn, name, recordtype string, ttl int, values []string) (response client.StandardResponse, err error) {
// UpdateDomainRecordByNameAndType changes the record with the given name and the given type in the zone attached to a domain
func (g *LiveDNS) UpdateDomainRecordByNameAndType(fqdn, name, recordtype string, ttl int, values []string) (response client.StandardResponse, err error) {
_, err = g.client.Put("domains/"+fqdn+"/records/"+name+"/"+recordtype,
DomainRecord{
RrsetType: recordtype,
RrsetTTL: ttl,
RrsetValues: values,
},

99
vendor/github.com/tiramiseb/go-gandi/livedns/keys.go generated vendored Normal file
View File

@ -0,0 +1,99 @@
package livedns
import "github.com/tiramiseb/go-gandi/internal/client"
// SigningKey holds data about a DNSSEC signing key
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"`
}
type configSamples struct {
Bind string `json:"bind,omitempty"`
Knot string `json:"knot,omitempty"`
NSD string `json:"nsd,omitempty"`
PowerDNS string `json:"powerdns,omitempty"`
}
// TSIGKey describes the TSIG key associated with an AXFR secondary
type TSIGKey struct {
KeyHREF string `json:"href,omitempty"`
ID string `json:"id,omitempty"`
KeyName string `json:"key_name,omitempty"`
Secret string `json:"secret,omitempty"`
ConfigSamples configSamples `json:"config_samples,omitempty"`
}
// GetTSIGKeys retrieves all the TSIG keys for the account
func (g *LiveDNS) GetTSIGKeys() (response []TSIGKey, err error) {
_, err = g.client.Get("axfr/tsig", nil, &response)
return
}
// GetTSIGKey retrieves the specified TSIG key
func (g *LiveDNS) GetTSIGKey(id string) (response TSIGKey, err error) {
_, err = g.client.Get("axfr/tsig/"+id, nil, &response)
return
}
// CreateTSIGKey creates a TSIG key
func (g *LiveDNS) CreateTSIGKey(fqdn string) (response TSIGKey, err error) {
_, err = g.client.Post("axfr/tsig", nil, &response)
return
}
// GetDomainTSIGKeys retrieves the specified TSIG key
func (g *LiveDNS) GetDomainTSIGKeys(fqdn string) (response []TSIGKey, err error) {
_, err = g.client.Get("domains/"+fqdn+"/axfr/tsig", nil, &response)
return
}
// AssociateTSIGKeyWithDomain retrieves the specified TSIG key
func (g *LiveDNS) AssociateTSIGKeyWithDomain(fqdn string, id string) (response client.StandardResponse, err error) {
_, err = g.client.Put("domains/"+fqdn+"/axfr/tsig/"+id, nil, &response)
return
}
// RemoveTSIGKeyFromDomain retrieves the specified TSIG key
func (g *LiveDNS) RemoveTSIGKeyFromDomain(fqdn string, id string) (err error) {
_, err = g.client.Delete("domains/"+fqdn+"/axfr/tsig/"+id, nil, nil)
return
}
// SignDomain creates a DNSKEY and asks Gandi servers to automatically sign the domain
func (g *LiveDNS) SignDomain(fqdn string) (response client.StandardResponse, err error) {
f := SigningKey{Flags: 257}
_, err = g.client.Post("domains/"+fqdn+"/keys", f, &response)
return
}
// GetDomainKeys returns data about the signing keys created for a domain
func (g *LiveDNS) GetDomainKeys(fqdn string) (keys []SigningKey, err error) {
_, err = g.client.Get("domains/"+fqdn+"/keys", nil, &keys)
return
}
// GetDomainKey deletes a signing key from a domain
func (g *LiveDNS) GetDomainKey(fqdn, uuid string) (key SigningKey, err error) {
_, err = g.client.Get("domains/"+fqdn+"/keys/"+uuid, nil, &key)
return
}
// DeleteDomainKey deletes a signing key from a domain
func (g *LiveDNS) DeleteDomainKey(fqdn, uuid string) (err error) {
_, err = g.client.Delete("domains/"+fqdn+"/keys/"+uuid, nil, nil)
return
}
// UpdateDomainKey updates a signing key for a domain (only the deleted status, actually...)
func (g *LiveDNS) UpdateDomainKey(fqdn, uuid string, deleted bool) (err error) {
_, err = g.client.Put("domains/"+fqdn+"/keys/"+uuid, SigningKey{Deleted: &deleted}, nil)
return
}

View File

@ -1,29 +0,0 @@
package livedns
import "github.com/tiramiseb/go-gandi/internal/client"
// Snapshot represents a zone snapshot
type Snapshot struct {
UUID string `json:"uuid,omitempty"`
DateCreated string `json:"date_created,omitempty"`
ZoneUUID string `json:"zone_uuid,omitempty"`
ZoneData []DomainRecord `json:"zone_data,omitempty"`
}
// ListSnapshots lists all domains
func (g *LiveDNS) ListSnapshots(fqdn string) (snapshots []Snapshot, err error) {
_, err = g.client.Get("domains/"+fqdn+"/snapshots", nil, &snapshots)
return
}
// CreateSnapshot creates a domain
func (g *LiveDNS) CreateSnapshot(fqdn string) (response client.StandardResponse, err error) {
_, err = g.client.Post("domains/"+fqdn+"/snapshots", nil, &response)
return
}
// GetSnapshot returns a domain
func (g *LiveDNS) GetSnapshot(fqdn, snapUUID string) (snapshot Snapshot, err error) {
_, err = g.client.Get("domains/"+fqdn+"/snapshots/"+snapUUID, nil, &snapshot)
return
}

View File

@ -0,0 +1,41 @@
package livedns
import (
"time"
"github.com/tiramiseb/go-gandi/internal/client"
)
// Snapshot represents a point in time record of a domain
type Snapshot struct {
Automatic *bool `json:"automatic,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
SnapshotHREF string `json:"snapshot_href,omitempty"`
ZoneData []DomainRecord `json:"zone_data,omitempty"`
}
// ListSnapshots lists all snapshots for a domain
func (g *LiveDNS) ListSnapshots(fqdn string) (snapshots []Snapshot, err error) {
_, err = g.client.Get("domains/"+fqdn+"/snapshots", nil, &snapshots)
return
}
// CreateSnapshot creates a snapshot for a domain
func (g *LiveDNS) CreateSnapshot(fqdn string) (response client.StandardResponse, err error) {
_, err = g.client.Post("domains/"+fqdn+"/snapshots", nil, &response)
return
}
// GetSnapshot returns a snapshot for a domain
func (g *LiveDNS) GetSnapshot(fqdn, snapUUID string) (snapshot Snapshot, err error) {
_, err = g.client.Get("domains/"+fqdn+"/snapshots/"+snapUUID, nil, &snapshot)
return
}
// DeleteSnapshot deletes a snapshot for a domain
func (g *LiveDNS) DeleteSnapshot(fqdn, snapUUID string) (err error) {
_, err = g.client.Delete("domains/"+fqdn+"/snapshots/"+snapUUID, nil, nil)
return
}