From 1616c50ba7988de026de329e7494dcaaf2063b3c Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Thu, 27 Feb 2020 12:06:25 -0500 Subject: [PATCH] GANDI_V5: Upgrade to newest github.com/tiramiseb/go-gandi --- go.mod | 2 +- go.sum | 4 +- providers/gandi_v5/gandi_v5Provider.go | 2 +- .../tiramiseb/go-gandi/livedns/domain.go | 58 +++-------- .../go-gandi/livedns/domainrecord.go | 21 ++-- .../tiramiseb/go-gandi/livedns/keys.go | 99 +++++++++++++++++++ .../tiramiseb/go-gandi/livedns/snapshot.go | 29 ------ .../tiramiseb/go-gandi/livedns/snapshots.go | 41 ++++++++ vendor/modules.txt | 2 +- 9 files changed, 171 insertions(+), 87 deletions(-) create mode 100644 vendor/github.com/tiramiseb/go-gandi/livedns/keys.go delete mode 100644 vendor/github.com/tiramiseb/go-gandi/livedns/snapshot.go create mode 100644 vendor/github.com/tiramiseb/go-gandi/livedns/snapshots.go diff --git a/go.mod b/go.mod index 8cb60991f..9bda4bffe 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,7 @@ require ( github.com/tdewolff/minify v2.3.6+incompatible github.com/tdewolff/parse v2.3.4+incompatible // indirect github.com/tdewolff/test v1.0.6 // indirect - github.com/tiramiseb/go-gandi v0.0.0-20200128175142-df8b8e9d23a1 + github.com/tiramiseb/go-gandi v0.0.0-20200227122905-7601fc3acbaa github.com/urfave/cli/v2 v2.1.1 github.com/vultr/govultr v0.2.0 golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d // indirect diff --git a/go.sum b/go.sum index 27d51114b..3877ba6e4 100644 --- a/go.sum +++ b/go.sum @@ -230,8 +230,8 @@ github.com/tdewolff/parse v2.3.4+incompatible h1:x05/cnGwIMf4ceLuDMBOdQ1qGniMoxp github.com/tdewolff/parse v2.3.4+incompatible/go.mod h1:8oBwCsVmUkgHO8M5iCzSIDtpzXOT0WXX9cWhz+bIzJQ= github.com/tdewolff/test v1.0.6 h1:76mzYJQ83Op284kMT+63iCNCI7NEERsIN8dLM+RiKr4= github.com/tdewolff/test v1.0.6/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= -github.com/tiramiseb/go-gandi v0.0.0-20200128175142-df8b8e9d23a1 h1:FOkGM6K21IiXFnX1UQ47yPa+awSeszBevK63k70Zggo= -github.com/tiramiseb/go-gandi v0.0.0-20200128175142-df8b8e9d23a1/go.mod h1:wevS0bE43PMSmEldbtya+tp+Ow180ftEPix8Onwh+E4= +github.com/tiramiseb/go-gandi v0.0.0-20200227122905-7601fc3acbaa h1:V0cb7c74KYakwwROlFGVlqEz3V7AW2JnIpSP6zSMdPg= +github.com/tiramiseb/go-gandi v0.0.0-20200227122905-7601fc3acbaa/go.mod h1:wevS0bE43PMSmEldbtya+tp+Ow180ftEPix8Onwh+E4= github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k= github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= github.com/vultr/govultr v0.2.0 h1:CZSNNCk+PHz9hzmfH2PFGkDgc3qNetwZqtcaqL8shlg= diff --git a/providers/gandi_v5/gandi_v5Provider.go b/providers/gandi_v5/gandi_v5Provider.go index ad626eb98..a04cd34b7 100644 --- a/providers/gandi_v5/gandi_v5Provider.go +++ b/providers/gandi_v5/gandi_v5Provider.go @@ -236,7 +236,7 @@ func (client *api) GenerateDomainCorrections(dc *models.DomainConfig, existing m &models.Correction{ Msg: msg, F: func() error { - res, err := g.ChangeDomainRecordsWithName(domain, shortname, ns) + res, err := g.UpdateDomainRecordsByName(domain, shortname, ns) if err != nil { return fmt.Errorf("%+v: %w", res, err) } diff --git a/vendor/github.com/tiramiseb/go-gandi/livedns/domain.go b/vendor/github.com/tiramiseb/go-gandi/livedns/domain.go index 6c6eae745..587ab31a4 100644 --- a/vendor/github.com/tiramiseb/go-gandi/livedns/domain.go +++ b/vendor/github.com/tiramiseb/go-gandi/livedns/domain.go @@ -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 } diff --git a/vendor/github.com/tiramiseb/go-gandi/livedns/domainrecord.go b/vendor/github.com/tiramiseb/go-gandi/livedns/domainrecord.go index e9be7bc81..5b2c5270f 100644 --- a/vendor/github.com/tiramiseb/go-gandi/livedns/domainrecord.go +++ b/vendor/github.com/tiramiseb/go-gandi/livedns/domainrecord.go @@ -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, }, diff --git a/vendor/github.com/tiramiseb/go-gandi/livedns/keys.go b/vendor/github.com/tiramiseb/go-gandi/livedns/keys.go new file mode 100644 index 000000000..588b881d2 --- /dev/null +++ b/vendor/github.com/tiramiseb/go-gandi/livedns/keys.go @@ -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 +} diff --git a/vendor/github.com/tiramiseb/go-gandi/livedns/snapshot.go b/vendor/github.com/tiramiseb/go-gandi/livedns/snapshot.go deleted file mode 100644 index 36c9c3e28..000000000 --- a/vendor/github.com/tiramiseb/go-gandi/livedns/snapshot.go +++ /dev/null @@ -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 -} diff --git a/vendor/github.com/tiramiseb/go-gandi/livedns/snapshots.go b/vendor/github.com/tiramiseb/go-gandi/livedns/snapshots.go new file mode 100644 index 000000000..581b4d62e --- /dev/null +++ b/vendor/github.com/tiramiseb/go-gandi/livedns/snapshots.go @@ -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 +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 0e762dc72..66ea385a8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -239,7 +239,7 @@ github.com/tdewolff/parse github.com/tdewolff/parse/buffer github.com/tdewolff/parse/json github.com/tdewolff/parse/strconv -# github.com/tiramiseb/go-gandi v0.0.0-20200128175142-df8b8e9d23a1 +# github.com/tiramiseb/go-gandi v0.0.0-20200227122905-7601fc3acbaa github.com/tiramiseb/go-gandi github.com/tiramiseb/go-gandi/domain github.com/tiramiseb/go-gandi/internal/client