2020-01-27 21:25:20 +08:00
|
|
|
package internetbs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
Switch to Go 1.13 error wrapping (#604)
* Replaced errors.Wrap with fmt.Errorf (#589)
* Find: errors\.Wrap\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Replaced errors.Wrapf with fmt.Errorf (#589)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])(,[^)]+)\)
* Replace: fmt.Errorf($2: %w$3$4, $1)
* Replaced errors.Errorf with fmt.Errorf (#589)
* Find: errors\.Errorf
Replace: fmt.Errorf
* Cleaned up remaining imports
* Cleanup
* Regenerate provider support matrix
This was broken by #533 ... and it's now the third time this has been missed.
2020-01-29 00:06:56 +08:00
|
|
|
|
2020-04-15 04:47:30 +08:00
|
|
|
"github.com/StackExchange/dnscontrol/v3/models"
|
|
|
|
"github.com/StackExchange/dnscontrol/v3/providers"
|
2020-01-27 21:25:20 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Internet.bs Registrator:
|
|
|
|
|
|
|
|
Info required in `creds.json`:
|
|
|
|
- api-key ApiKey
|
|
|
|
- password Your account password
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
providers.RegisterRegistrarType("INTERNETBS", newInternetBs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newInternetBs(m map[string]string) (providers.Registrar, error) {
|
|
|
|
api := &api{}
|
|
|
|
|
|
|
|
api.key, api.password = m["api-key"], m["password"]
|
|
|
|
if api.key == "" || api.password == "" {
|
Switch to Go 1.13 error wrapping (#604)
* Replaced errors.Wrap with fmt.Errorf (#589)
* Find: errors\.Wrap\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Replaced errors.Wrapf with fmt.Errorf (#589)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])(,[^)]+)\)
* Replace: fmt.Errorf($2: %w$3$4, $1)
* Replaced errors.Errorf with fmt.Errorf (#589)
* Find: errors\.Errorf
Replace: fmt.Errorf
* Cleaned up remaining imports
* Cleanup
* Regenerate provider support matrix
This was broken by #533 ... and it's now the third time this has been missed.
2020-01-29 00:06:56 +08:00
|
|
|
return nil, fmt.Errorf("missing Internet.bs api-key and password")
|
2020-01-27 21:25:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return api, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRegistrarCorrections gathers corrections that would being n to match dc.
|
|
|
|
func (c *api) GetRegistrarCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
|
|
|
|
nss, err := c.getNameservers(dc.Name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
foundNameservers := strings.Join(nss, ",")
|
|
|
|
|
|
|
|
expected := []string{}
|
|
|
|
for _, ns := range dc.Nameservers {
|
|
|
|
name := strings.TrimRight(ns.Name, ".")
|
|
|
|
expected = append(expected, name)
|
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|