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

@ -89,8 +89,8 @@
<td class="success">
<i class="fa fa-check text-success" aria-hidden="true"></i>
</td>
<td class="danger">
<i class="fa fa-times text-danger" aria-hidden="true"></i>
<td class="success">
<i class="fa fa-check text-success" aria-hidden="true"></i>
</td>
<td class="danger">
<i class="fa fa-times text-danger" aria-hidden="true"></i>

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)

View File

@ -16,7 +16,8 @@ func New(c *client.Client) *Domain {
// Check the availability of some domain
func (self *Domain) Available(name string) (string, error) {
var result map[string]interface{}
params := []interface{}{self.Key, name}
domain := []string{name}
params := []interface{}{self.Key, domain}
if err := self.Call("domain.available", params, &result); err != nil {
return "", err
}

View File

@ -0,0 +1,24 @@
package zone
import (
"github.com/prasmussen/gandi-api/client"
"github.com/prasmussen/gandi-api/operation"
)
type Nameservers struct {
*client.Client
}
func New(c *client.Client) *Nameservers {
return &Nameservers{c}
}
// Set the current zone of a domain
func (self *Nameservers) Set(domainName string, nameservers []string) (*operation.OperationInfo, error) {
var res map[string]interface{}
params := []interface{}{self.Key, domainName, nameservers}
if err := self.Call("domain.nameservers.set", params, &res); err != nil {
return nil, err
}
return operation.ToOperationInfo(res), nil
}

View File

@ -65,7 +65,7 @@ func (self *Record) Add(args RecordAdd) (*RecordInfo, error) {
}
// Remove a record from a zone/version
func (self *Record) Delete(zoneId, version, recordId int64) (bool, error) {
func (self *Record) Delete(zoneId, version int64, recordId string) (bool, error) {
var res int64
deleteArgs := map[string]interface{}{"id": recordId}
params := []interface{}{self.Key, zoneId, version, deleteArgs}

38
vendor/vendor.json vendored
View File

@ -335,44 +335,50 @@
{
"checksumSHA1": "nS4kKHjMlJpQg3sixqelpCg1jyk=",
"path": "github.com/prasmussen/gandi-api/client",
"revision": "931915c3a2ca2661373f0b25bbedfee9e1958d2b",
"revisionTime": "2017-09-08T20:15:21Z"
"revision": "a23dc46a847ad0f56c9d66cd84ffeeb002f2c6d3",
"revisionTime": "2017-11-24T17:13:09Z"
},
{
"checksumSHA1": "tT8xSQc+QM3/JPs16WjDtTFY7j0=",
"checksumSHA1": "US0LGupyHvXgr2iDH7kw4f7KOcc=",
"path": "github.com/prasmussen/gandi-api/domain",
"revision": "931915c3a2ca2661373f0b25bbedfee9e1958d2b",
"revisionTime": "2017-09-08T20:15:21Z"
"revision": "a23dc46a847ad0f56c9d66cd84ffeeb002f2c6d3",
"revisionTime": "2017-11-24T17:13:09Z"
},
{
"checksumSHA1": "QCTGEMnU3WqIX51TqbRvAuwu4Wo=",
"path": "github.com/prasmussen/gandi-api/domain/nameservers",
"revision": "a23dc46a847ad0f56c9d66cd84ffeeb002f2c6d3",
"revisionTime": "2017-11-24T17:13:09Z"
},
{
"checksumSHA1": "/t4nBKtJF6W3PHzTBNAzgcw54GU=",
"path": "github.com/prasmussen/gandi-api/domain/zone",
"revision": "931915c3a2ca2661373f0b25bbedfee9e1958d2b",
"revisionTime": "2017-09-08T20:15:21Z"
"revision": "a23dc46a847ad0f56c9d66cd84ffeeb002f2c6d3",
"revisionTime": "2017-11-24T17:13:09Z"
},
{
"checksumSHA1": "wers/RRtpv1SXRpnUg6ptC1nKoM=",
"checksumSHA1": "wmLJwLc3SlIGhio+vWofJq4XSTU=",
"path": "github.com/prasmussen/gandi-api/domain/zone/record",
"revision": "931915c3a2ca2661373f0b25bbedfee9e1958d2b",
"revisionTime": "2017-09-08T20:15:21Z"
"revision": "a23dc46a847ad0f56c9d66cd84ffeeb002f2c6d3",
"revisionTime": "2017-11-24T17:13:09Z"
},
{
"checksumSHA1": "avzpVkEeXzDiaNLsl4agXWm9tm0=",
"path": "github.com/prasmussen/gandi-api/domain/zone/version",
"revision": "931915c3a2ca2661373f0b25bbedfee9e1958d2b",
"revisionTime": "2017-09-08T20:15:21Z"
"revision": "a23dc46a847ad0f56c9d66cd84ffeeb002f2c6d3",
"revisionTime": "2017-11-24T17:13:09Z"
},
{
"checksumSHA1": "txVNPkzE0Jkag20VZ1hLj/Td+O4=",
"path": "github.com/prasmussen/gandi-api/operation",
"revision": "931915c3a2ca2661373f0b25bbedfee9e1958d2b",
"revisionTime": "2017-09-08T20:15:21Z"
"revision": "a23dc46a847ad0f56c9d66cd84ffeeb002f2c6d3",
"revisionTime": "2017-11-24T17:13:09Z"
},
{
"checksumSHA1": "FwIh1Rk/XNANaxCz3Fw/vQ3Hu5E=",
"path": "github.com/prasmussen/gandi-api/util",
"revision": "931915c3a2ca2661373f0b25bbedfee9e1958d2b",
"revisionTime": "2017-09-08T20:15:21Z"
"revision": "a23dc46a847ad0f56c9d66cd84ffeeb002f2c6d3",
"revisionTime": "2017-11-24T17:13:09Z"
},
{
"checksumSHA1": "NLTyYVX4dn8jV1iad7p494AiZ8E=",