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:
committed by
Tom Limoncelli
parent
c0a68fae4f
commit
2d88d81392
1
OWNERS
1
OWNERS
@ -8,6 +8,7 @@ providers/dnsimple @aeden
|
|||||||
providers/gandi @TomOnTime
|
providers/gandi @TomOnTime
|
||||||
# providers/gcloud
|
# providers/gcloud
|
||||||
providers/hexonet @papakai
|
providers/hexonet @papakai
|
||||||
|
providers/internetbs @pragmaton
|
||||||
providers/linode @koesie10
|
providers/linode @koesie10
|
||||||
providers/namecheap @captncraig
|
providers/namecheap @captncraig
|
||||||
# providers/namedotcom
|
# providers/namedotcom
|
||||||
|
@ -24,6 +24,7 @@ Currently supported DNS providers:
|
|||||||
- Gandi
|
- Gandi
|
||||||
- Google
|
- Google
|
||||||
- HEXONET
|
- HEXONET
|
||||||
|
- Internet.bs
|
||||||
- Linode
|
- Linode
|
||||||
- Namecheap
|
- Namecheap
|
||||||
- Name.com
|
- Name.com
|
||||||
|
40
docs/_providers/internetbs.md
Normal file
40
docs/_providers/internetbs.md
Normal 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`
|
@ -66,6 +66,7 @@ Maintainers of contributed providers:
|
|||||||
* dnsimple @aeden
|
* dnsimple @aeden
|
||||||
* gandi @TomOnTime
|
* gandi @TomOnTime
|
||||||
* HEXONET @papakai
|
* HEXONET @papakai
|
||||||
|
* Internet.bs @pragmaton
|
||||||
* Linode @koesie10
|
* Linode @koesie10
|
||||||
* namecheap @captncraig
|
* namecheap @captncraig
|
||||||
* ns1 @captncraig
|
* ns1 @captncraig
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
_ "github.com/StackExchange/dnscontrol/providers/gandi_v5"
|
_ "github.com/StackExchange/dnscontrol/providers/gandi_v5"
|
||||||
_ "github.com/StackExchange/dnscontrol/providers/gcloud"
|
_ "github.com/StackExchange/dnscontrol/providers/gcloud"
|
||||||
_ "github.com/StackExchange/dnscontrol/providers/hexonet"
|
_ "github.com/StackExchange/dnscontrol/providers/hexonet"
|
||||||
|
_ "github.com/StackExchange/dnscontrol/providers/internetbs"
|
||||||
_ "github.com/StackExchange/dnscontrol/providers/linode"
|
_ "github.com/StackExchange/dnscontrol/providers/linode"
|
||||||
_ "github.com/StackExchange/dnscontrol/providers/namecheap"
|
_ "github.com/StackExchange/dnscontrol/providers/namecheap"
|
||||||
_ "github.com/StackExchange/dnscontrol/providers/namedotcom"
|
_ "github.com/StackExchange/dnscontrol/providers/namedotcom"
|
||||||
|
88
providers/internetbs/api.go
Normal file
88
providers/internetbs/api.go
Normal 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
|
||||||
|
}
|
64
providers/internetbs/internetbsProvider.go
Normal file
64
providers/internetbs/internetbsProvider.go
Normal 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
|
||||||
|
}
|
Reference in New Issue
Block a user