mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
NEW PROVIDER: CSCGLOBAL as DNS Service Provider (#1516)
* Move the registrar features to a separate file * Prepare the testing framework * Roughed out functions * Fix up structs * WIP! * First tests pass * wip! * Flesh out remaining rTypes, get nameservers, etc * Fix TXT records * Clean up code * More cleanups. Fix CAA/SRV * Linting * Cleanups/linting * Fix CAA [more] and more cleanups * CSC does not like very long txt records * Use timer only when interactive * Disable CAA for now * Update docs * Remove debug printf * add go-isatty * cleanups
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
package cscglobal
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/StackExchange/dnscontrol/v3/models"
|
||||
"github.com/StackExchange/dnscontrol/v3/providers"
|
||||
)
|
||||
|
||||
@@ -19,12 +18,32 @@ Info required in `creds.json`:
|
||||
- notification_emails (optional) Comma separated list of email addresses to send notifications to
|
||||
*/
|
||||
|
||||
func init() {
|
||||
providers.RegisterRegistrarType("CSCGLOBAL", newCscGlobal)
|
||||
type providerClient struct {
|
||||
key string
|
||||
token string
|
||||
notifyEmails []string
|
||||
}
|
||||
|
||||
func newCscGlobal(m map[string]string) (providers.Registrar, error) {
|
||||
api := &cscglobalProvider{}
|
||||
var features = providers.DocumentationNotes{
|
||||
providers.CanGetZones: providers.Can(),
|
||||
//providers.CanUseCAA: providers.Can(),
|
||||
providers.CanUseSRV: providers.Can(),
|
||||
providers.DocOfficiallySupported: providers.Can(),
|
||||
}
|
||||
|
||||
// Set cscDebug to true if you want to see the JSON of important API requests and responses.
|
||||
var cscDebug = false
|
||||
|
||||
func newReg(conf map[string]string) (providers.Registrar, error) {
|
||||
return newProvider(conf)
|
||||
}
|
||||
|
||||
func newDsp(conf map[string]string, meta json.RawMessage) (providers.DNSServiceProvider, error) {
|
||||
return newProvider(conf)
|
||||
}
|
||||
|
||||
func newProvider(m map[string]string) (*providerClient, error) {
|
||||
api := &providerClient{}
|
||||
|
||||
api.key, api.token = m["api-key"], m["user-token"]
|
||||
if api.key == "" || api.token == "" {
|
||||
@@ -38,35 +57,12 @@ func newCscGlobal(m map[string]string) (providers.Registrar, error) {
|
||||
return api, nil
|
||||
}
|
||||
|
||||
// GetRegistrarCorrections gathers corrections that would being n to match dc.
|
||||
func (c *cscglobalProvider) GetRegistrarCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
|
||||
nss, err := c.getNameservers(dc.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
foundNameservers := strings.Join(nss, ",")
|
||||
func init() {
|
||||
providers.RegisterRegistrarType("CSCGLOBAL", newReg)
|
||||
|
||||
expected := []string{}
|
||||
for _, ns := range dc.Nameservers {
|
||||
if ns.Name[len(ns.Name)-1] == '.' {
|
||||
// When this code was written ns.Name never included a single trailing dot.
|
||||
// If that changes, the code should change too.
|
||||
return nil, fmt.Errorf("name server includes a trailing dot, has the API changed?")
|
||||
}
|
||||
expected = append(expected, ns.Name)
|
||||
fns := providers.DspFuncs{
|
||||
Initializer: newDsp,
|
||||
RecordAuditor: AuditRecords,
|
||||
}
|
||||
sort.Strings(expected)
|
||||
expectedNameservers := strings.Join(expected, ",")
|
||||
|
||||
if foundNameservers != expectedNameservers {
|
||||
return []*models.Correction{
|
||||
{
|
||||
Msg: fmt.Sprintf("Update nameservers %s -> %s", foundNameservers, expectedNameservers),
|
||||
F: func() error {
|
||||
return c.updateNameservers(expected, dc.Name)
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
return nil, nil
|
||||
providers.RegisterDomainServiceProviderType("CSCGLOBAL", fns, features)
|
||||
}
|
||||
|
Reference in New Issue
Block a user