github.com/teknogeek/dnscontrol/v2@v2.10.1-0.20200227202244-ae299b55ba42/providers/internetbs/internetbsProvider.go (about) 1 package internetbs 2 3 import ( 4 "fmt" 5 "sort" 6 "strings" 7 8 "github.com/StackExchange/dnscontrol/v2/models" 9 "github.com/StackExchange/dnscontrol/v2/providers" 10 ) 11 12 /* 13 14 Internet.bs Registrator: 15 16 Info required in `creds.json`: 17 - api-key ApiKey 18 - password Your account password 19 20 */ 21 22 func init() { 23 providers.RegisterRegistrarType("INTERNETBS", newInternetBs) 24 } 25 26 func newInternetBs(m map[string]string) (providers.Registrar, error) { 27 api := &api{} 28 29 api.key, api.password = m["api-key"], m["password"] 30 if api.key == "" || api.password == "" { 31 return nil, fmt.Errorf("missing Internet.bs api-key and password") 32 } 33 34 return api, nil 35 } 36 37 // GetRegistrarCorrections gathers corrections that would being n to match dc. 38 func (c *api) GetRegistrarCorrections(dc *models.DomainConfig) ([]*models.Correction, error) { 39 nss, err := c.getNameservers(dc.Name) 40 if err != nil { 41 return nil, err 42 } 43 foundNameservers := strings.Join(nss, ",") 44 45 expected := []string{} 46 for _, ns := range dc.Nameservers { 47 name := strings.TrimRight(ns.Name, ".") 48 expected = append(expected, name) 49 } 50 sort.Strings(expected) 51 expectedNameservers := strings.Join(expected, ",") 52 53 if foundNameservers != expectedNameservers { 54 return []*models.Correction{ 55 { 56 Msg: fmt.Sprintf("Update nameservers (%s) -> (%s)", foundNameservers, expectedNameservers), 57 F: func() error { 58 return c.updateNameservers(expected, dc.Name) 59 }, 60 }, 61 }, nil 62 } 63 return nil, nil 64 }