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

GANDI: Registrar support (#274)

* GANDI: add registrar support for changing nameservers. #87

* Update docs with Gandi registrar support #87

* Updated dependencies for Gandi Registrar Support #87
This commit is contained in:
Philipp Hug
2017-11-27 19:04:24 +01:00
committed by Craig Peterson
parent ccf28349ce
commit 53b72f39a8
7 changed files with 98 additions and 22 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"log"
"sort"
"github.com/StackExchange/dnscontrol/models"
"github.com/StackExchange/dnscontrol/providers"
@@ -31,8 +32,9 @@ var docNotes = providers.DocumentationNotes{
}
func init() {
providers.RegisterDomainServiceProviderType("GANDI", newGandi, providers.CanUsePTR,
providers.RegisterDomainServiceProviderType("GANDI", newDsp, providers.CanUsePTR,
providers.CanUseSRV, docNotes, providers.CantUseNOPURGE)
providers.RegisterRegistrarType("GANDI", newReg)
}
type GandiApi struct {
@@ -150,7 +152,15 @@ func (c *GandiApi) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Corr
return corrections, nil
}
func newGandi(m map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) {
func newDsp(conf map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) {
return newGandi(conf, metadata)
}
func newReg(conf map[string]string) (providers.Registrar, error) {
return newGandi(conf, nil)
}
func newGandi(m map[string]string, metadata json.RawMessage) (*GandiApi, error) {
api := &GandiApi{}
api.ApiKey = m["apikey"]
if api.ApiKey == "" {
@@ -159,3 +169,29 @@ func newGandi(m map[string]string, metadata json.RawMessage) (providers.DNSServi
return api, nil
}
func (c *GandiApi) GetRegistrarCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
domaininfo, err := c.getDomainInfo(dc.Name)
if err != nil {
return nil, err
}
sort.Strings(domaininfo.Nameservers)
found := strings.Join(domaininfo.Nameservers, ",")
desiredNs := []string{}
for _, d := range dc.Nameservers {
desiredNs = append(desiredNs, d.Name)
}
sort.Strings(desiredNs)
desired := strings.Join(desiredNs, ",")
if found != desired {
return []*models.Correction{
{
Msg: fmt.Sprintf("Change Nameservers from '%s' to '%s'", found, desired),
F: func() (err error) {
_, err = c.setDomainNameservers(dc.Name, desiredNs)
return
}},
}, nil
}
return nil, nil
}

View File

@@ -5,9 +5,11 @@ import (
gandiclient "github.com/prasmussen/gandi-api/client"
gandidomain "github.com/prasmussen/gandi-api/domain"
gandinameservers "github.com/prasmussen/gandi-api/domain/nameservers"
gandizone "github.com/prasmussen/gandi-api/domain/zone"
gandirecord "github.com/prasmussen/gandi-api/domain/zone/record"
gandiversion "github.com/prasmussen/gandi-api/domain/zone/version"
gandioperation "github.com/prasmussen/gandi-api/operation"
"github.com/StackExchange/dnscontrol/models"
"github.com/miekg/dns/dnsutil"
@@ -39,6 +41,13 @@ func (c *GandiApi) fetchDomainInfo(fqdn string) (*gandidomain.DomainInfo, error)
return domain.Info(fqdn)
}
// setDomainNameservers updates the nameservers of a domain.
func (c *GandiApi) setDomainNameservers(fqdn string, nameservers []string) (*gandioperation.OperationInfo, error) {
gc := gandiclient.New(c.ApiKey, gandiclient.Production)
nameserversapi := gandinameservers.New(gc)
return nameserversapi.Set(fqdn, nameservers)
}
// getRecordsForDomain returns a list of records for a zone.
func (c *GandiApi) getZoneRecords(zoneid int64, origin string) ([]*models.RecordConfig, error) {
gc := gandiclient.New(c.ApiKey, gandiclient.Production)