From d5665ceaf65ca93a0d06075c2eeea642e6935581 Mon Sep 17 00:00:00 2001 From: Julius Rickert Date: Tue, 22 Feb 2022 16:54:02 +0100 Subject: [PATCH] Documentation: Customizing nameservers for hosting.de provider (#1396) * Add support for default nameservers Uses provider metadata with default_ns key. Fixes #1401. * Fix formatting * Add documentation on custom nameservers * Rework hosting.de documentation Separate usage with hosting.de and usage with compatible providers. Co-authored-by: Tom Limoncelli --- docs/_providers/hostingde.md | 44 ++++++++++++++++-------- providers/hostingde/api.go | 3 +- providers/hostingde/hostingdeProvider.go | 40 +++++++++++---------- 3 files changed, 53 insertions(+), 34 deletions(-) diff --git a/docs/_providers/hostingde.md b/docs/_providers/hostingde.md index 0287342cb..68300a6b9 100644 --- a/docs/_providers/hostingde.md +++ b/docs/_providers/hostingde.md @@ -4,33 +4,26 @@ title: hosting.de Provider layout: default jsId: hostingde --- + # hosting.de Provider ## Configuration In your credentials file, you must provide your [`authToken` and optionally an `ownerAccountId`](https://www.hosting.de/api/#requests-and-authentication). -**If you want to use this provider with http.net or a demo system you need to provide a custom `baseURL`.** - -* hosting.de (default): `https://secure.hosting.de` -* http.net: `https://partner.http.net` -* Demo: `https://demo.routing.net` +### Example `creds.json` ```json { "hosting.de": { "authToken": "YOUR_API_KEY" - }, - "http.net": { - "authToken": "YOUR_API_KEY", - "baseURL": "https://partner.http.net" } } ``` ## Usage -Example JavaScript: +### Example `dnsconfig.js` ```js var REG_HOSTINGDE = NewRegistrar('hosting.de', 'HOSTINGDE') @@ -41,15 +34,29 @@ D('example.tld', REG_HOSTINGDE, DnsProvider(DNS_HOSTINGDE), ); ``` -## Customize nameservers +## Using this provider with http.net and others -hosting.de has the concept of *nameserver sets* but this provider does not implement it. -The `HOSTINGDE` provider **ignores the default nameserver set** defined in your account! -Instead, it uses hosting.de's nameservers (`ns1.hosting.de.`, `ns2.hosting.de.`, and `ns3.hosting.de.`) by default, regardless of your account settings. +http.net and other DNS service providers use an API that is compatible with hosting.de's API. +Using them requires setting the `baseURL` and (optionally) overriding the default nameservers. -If you want to change this behaviour to, for example, use http.net's nameservers, you can do this by setting an array of strings called `default_ns` in the provider metadata: +### Example http.net configuration + +#### Example `creds.json` + +```json +{ + "http.net": { + "authToken": "YOUR_API_KEY", + "baseURL": "https://partner.http.net" + } +} +``` + +#### Example `dnsconfig.js` ```js +var REG_HTTPNET = NewRegistrar('http.net', 'HOSTINGDE'); + var DNS_HTTPNET = NewDnsProvider('http.net', 'HOSTINGDE', { default_ns: [ 'ns1.routing.net.', @@ -58,3 +65,10 @@ var DNS_HTTPNET = NewDnsProvider('http.net', 'HOSTINGDE', { ], }); ``` + +#### Why this works + +hosting.de has the concept of _nameserver sets_ but this provider does not implement it. +The `HOSTINGDE` provider **ignores the default nameserver set** defined in your account to avoid unintentional changes and consolidate the full configuration in DNSControl. +Instead, it uses hosting.de's nameservers (`ns1.hosting.de.`, `ns2.hosting.de.`, and `ns3.hosting.de.`) by default, regardless of your account settings. +Using the `default_ns` metadata, the default nameserver set can be overwritten. diff --git a/providers/hostingde/api.go b/providers/hostingde/api.go index e623a871f..a3e2e516c 100644 --- a/providers/hostingde/api.go +++ b/providers/hostingde/api.go @@ -17,6 +17,7 @@ type hostingdeProvider struct { authToken string ownerAccountID string baseURL string + nameservers []string } func (hp *hostingdeProvider) getDomainConfig(domain string) (*domainConfig, error) { @@ -51,7 +52,7 @@ func (hp *hostingdeProvider) createZone(domain string) error { } records := []*record{} - for _, ns := range defaultNameservers { + for _, ns := range hp.nameservers { records = append(records, &record{ Name: domain, Type: "NS", diff --git a/providers/hostingde/hostingdeProvider.go b/providers/hostingde/hostingdeProvider.go index 1235d45e7..9603bd1ae 100644 --- a/providers/hostingde/hostingdeProvider.go +++ b/providers/hostingde/hostingdeProvider.go @@ -11,7 +11,7 @@ import ( "github.com/StackExchange/dnscontrol/v3/providers" ) -var defaultNameservers = []string{"ns1.hosting.de", "ns2.hosting.de", "ns3.hosting.de"} +var defaultNameservers = []string{"ns1.hosting.de.", "ns2.hosting.de.", "ns3.hosting.de."} var features = providers.DocumentationNotes{ providers.CanAutoDNSSEC: providers.Unimplemented("Supported but not implemented yet."), @@ -40,7 +40,11 @@ func init() { providers.RegisterDomainServiceProviderType("HOSTINGDE", fns, features) } -func newHostingde(m map[string]string) (*hostingdeProvider, error) { +type providerMeta struct { + DefaultNS []string `json:"default_ns"` +} + +func newHostingde(m map[string]string, providermeta json.RawMessage) (*hostingdeProvider, error) { authToken, ownerAccountID, baseURL := m["authToken"], m["ownerAccountId"], m["baseURL"] if authToken == "" { @@ -56,33 +60,33 @@ func newHostingde(m map[string]string) (*hostingdeProvider, error) { authToken: authToken, ownerAccountID: ownerAccountID, baseURL: baseURL, + nameservers: defaultNameservers, + } + + if len(providermeta) > 0 { + var pm providerMeta + if err := json.Unmarshal(providermeta, &pm); err != nil { + return nil, fmt.Errorf("hosting.de: could not parse providermeta: %w", err) + } + + if len(pm.DefaultNS) > 0 { + hp.nameservers = pm.DefaultNS + } } return hp, nil } -func newHostingdeDsp(m map[string]string, raw json.RawMessage) (providers.DNSServiceProvider, error) { - return newHostingde(m) +func newHostingdeDsp(m map[string]string, providermeta json.RawMessage) (providers.DNSServiceProvider, error) { + return newHostingde(m, providermeta) } func newHostingdeReg(m map[string]string) (providers.Registrar, error) { - return newHostingde(m) + return newHostingde(m, json.RawMessage{}) } func (hp *hostingdeProvider) GetNameservers(domain string) ([]*models.Nameserver, error) { - src, err := hp.getRecords(domain) - if err != nil { - return nil, err - } - - var nameservers []string - for _, record := range src { - if record.Type == "NS" { - nameservers = append(nameservers, record.Content) - } - } - - return models.ToNameservers(nameservers) + return models.ToNameserversStripTD(hp.nameservers) } func (hp *hostingdeProvider) GetZoneRecords(domain string) (models.Records, error) {