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

NEW PROVIDER: Internet.bs (#590)

* Ineternet.bs: first version of provider
* Ineternet.bs: code and documentation cleanup
This commit is contained in:
Anton Yurchenko
2020-01-27 20:25:20 +07:00
committed by Tom Limoncelli
parent c0a68fae4f
commit 2d88d81392
7 changed files with 196 additions and 0 deletions

1
OWNERS
View File

@ -8,6 +8,7 @@ providers/dnsimple @aeden
providers/gandi @TomOnTime
# providers/gcloud
providers/hexonet @papakai
providers/internetbs @pragmaton
providers/linode @koesie10
providers/namecheap @captncraig
# providers/namedotcom

View File

@ -24,6 +24,7 @@ Currently supported DNS providers:
- Gandi
- Google
- HEXONET
- Internet.bs
- Linode
- Namecheap
- Name.com

View File

@ -0,0 +1,40 @@
---
name: Internet.bs
title: Internet.bs Provider
layout: default
jsId: INTERNETBS
---
# Internet.bs Provider
DNSControl's Internet.bs provider supports being a Registrar. Support for being a DNS Provider is not included, but could be added in the future.
## Configuration
In your credentials file, you must provide your API key and account password
{% highlight json %}
{
"internetbs": {
"api-key": "your-api-key",
"password": "account-password"
}
}
{% endhighlight %}
## Metadata
This provider does not recognize any special metadata fields unique to Internet.bs.
## Usage
Example Javascript:
{% highlight js %}
var REG_INTERNETBS = NewRegistrar('internetbs', 'INTERNETBS');
var GCLOUD = NewDnsProvider("gcloud", "GCLOUD"); // Any provider
D("example.tld", REG_INTERNETBS, DnsProvider(GCLOUD),
A("test","1.2.3.4")
);
{% endhighlight %}
## Activation
Pay attention, you need to define white list of IP for API. But you always can change it on `My Profile > Reseller Settings`

View File

@ -66,6 +66,7 @@ Maintainers of contributed providers:
* dnsimple @aeden
* gandi @TomOnTime
* HEXONET @papakai
* Internet.bs @pragmaton
* Linode @koesie10
* namecheap @captncraig
* ns1 @captncraig

View File

@ -15,6 +15,7 @@ import (
_ "github.com/StackExchange/dnscontrol/providers/gandi_v5"
_ "github.com/StackExchange/dnscontrol/providers/gcloud"
_ "github.com/StackExchange/dnscontrol/providers/hexonet"
_ "github.com/StackExchange/dnscontrol/providers/internetbs"
_ "github.com/StackExchange/dnscontrol/providers/linode"
_ "github.com/StackExchange/dnscontrol/providers/namecheap"
_ "github.com/StackExchange/dnscontrol/providers/namedotcom"

View File

@ -0,0 +1,88 @@
package internetbs
import (
"encoding/json"
"github.com/pkg/errors"
"io/ioutil"
"net/http"
"strings"
)
// Api layer for Internet.bs
type api struct {
key string
password string
}
type requestParams map[string]string
type errorResponse struct {
TransactID string `json:"transactid"`
Status string `json:"status"`
Message string `json:"message,omitempty"`
Code uint `json:"code,omitempty"`
}
type domainRecord struct {
Nameserver []string `json:"nameserver"`
}
func (c *api) getNameservers(domain string) ([]string, error) {
var bodyString, err = c.get("/Domain/Info", requestParams{"Domain": domain})
if err != nil {
return []string{}, errors.Errorf("Error fetching nameservers list from Internet.bs: %s", err)
}
var dr domainRecord
json.Unmarshal(bodyString, &dr)
ns := []string{}
for _, nameserver := range dr.Nameserver {
ns = append(ns, nameserver)
}
return ns, nil
}
func (c *api) updateNameservers(ns []string, domain string) error {
rec := requestParams{}
rec["Domain"] = domain
rec["Ns_list"] = strings.Join(ns, ",")
if _, err := c.get("/Domain/Update", rec); err != nil {
return errors.Errorf("Internet.ns: Error update NS : %s", err)
}
return nil
}
func (c *api) get(endpoint string, params requestParams) ([]byte, error) {
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.internet.bs/"+endpoint, nil)
q := req.URL.Query()
// Add auth params
q.Add("ApiKey", c.key)
q.Add("Password", c.password)
q.Add("ResponseFormat", "JSON")
for pName, pValue := range params {
q.Add(pName, pValue)
}
req.URL.RawQuery = q.Encode()
resp, err := client.Do(req)
if err != nil {
return []byte{}, err
}
bodyString, _ := ioutil.ReadAll(resp.Body)
// Got error from API ?
var errResp errorResponse
err = json.Unmarshal(bodyString, &errResp)
if errResp.Status == "FAILURE" {
return bodyString, errors.Errorf("Internet.bs API error: %s code: %d transactid: %s URL:%s%s ",
errResp.Message, errResp.Code, errResp.TransactID,
req.Host, req.URL.RequestURI())
}
return bodyString, nil
}

View File

@ -0,0 +1,64 @@
package internetbs
import (
"fmt"
"github.com/StackExchange/dnscontrol/models"
"github.com/StackExchange/dnscontrol/providers"
"github.com/pkg/errors"
"sort"
"strings"
)
/*
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 == "" {
return nil, errors.Errorf("missing Internet.bs api-key and password")
}
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
}