Skip to content

Commit 008c817

Browse files
authored
Add DNS provider for Core-Networks (#2101)
1 parent 19b535c commit 008c817

16 files changed

+1021
-31
lines changed

README.md

Lines changed: 30 additions & 30 deletions
Large diffs are not rendered by default.

cmd/zz_gen_cmd_dnshelp.go

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: "Core-Networks"
3+
date: 2019-03-03T16:39:46+01:00
4+
draft: false
5+
slug: corenetworks
6+
dnsprovider:
7+
since: "v4.20.0"
8+
code: "corenetworks"
9+
url: "https://www.core-networks.de/"
10+
---
11+
12+
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
13+
<!-- providers/dns/corenetworks/corenetworks.toml -->
14+
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
15+
16+
17+
Configuration for [Core-Networks](https://www.core-networks.de/).
18+
19+
20+
<!--more-->
21+
22+
- Code: `corenetworks`
23+
- Since: v4.20.0
24+
25+
26+
Here is an example bash command using the Core-Networks provider:
27+
28+
```bash
29+
CORENETWORKS_LOGIN="xxxx" \
30+
CORENETWORKS_PASSWORD="yyyy" \
31+
lego --email myemail@example.com --dns corenetworks --domains my.example.org run
32+
```
33+
34+
35+
36+
37+
## Credentials
38+
39+
| Environment Variable Name | Description |
40+
|-----------------------|-------------|
41+
| `CORENETWORKS_LOGIN` | The username of the API account |
42+
| `CORENETWORKS_PASSWORD` | The password |
43+
44+
The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
45+
More information [here]({{% ref "dns#configuration-and-credentials" %}}).
46+
47+
48+
## Additional Configuration
49+
50+
| Environment Variable Name | Description |
51+
|--------------------------------|-------------|
52+
| `CORENETWORKS_HTTP_TIMEOUT` | API request timeout |
53+
| `CORENETWORKS_POLLING_INTERVAL` | Time between DNS propagation check |
54+
| `CORENETWORKS_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
55+
| `CORENETWORKS_SEQUENCE_INTERVAL` | Time between sequential requests |
56+
| `CORENETWORKS_TTL` | The TTL of the TXT record used for the DNS challenge |
57+
58+
The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
59+
More information [here]({{% ref "dns#configuration-and-credentials" %}}).
60+
61+
62+
63+
64+
## More information
65+
66+
- [API documentation](https://beta.api.core-networks.de/doc/)
67+
68+
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
69+
<!-- providers/dns/corenetworks/corenetworks.toml -->
70+
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->

docs/data/zz_cli_help.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ To display the documentation for a specific DNS provider, run:
141141
$ lego dnshelp -c code
142142
143143
Supported DNS providers:
144-
acme-dns, alidns, allinkl, arvancloud, auroradns, autodns, azure, azuredns, bindman, bluecat, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, constellix, cpanel, derak, desec, designate, digitalocean, directadmin, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dynu, easydns, edgedns, efficientip, epik, exec, exoscale, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hosttech, httpnet, httpreq, huaweicloud, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, liara, lightsail, limacity, linode, liquidweb, loopia, luadns, mailinabox, manual, metaname, mijnhost, mittwald, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nifcloud, njalla, nodion, ns1, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rcodezero, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, selectelv2, selfhostde, servercow, shellrent, simply, sonic, stackpath, tencentcloud, timewebcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, volcengine, vscale, vultr, webnames, websupport, wedos, yandex, yandex360, yandexcloud, zoneee, zonomi
144+
acme-dns, alidns, allinkl, arvancloud, auroradns, autodns, azure, azuredns, bindman, bluecat, brandit, bunny, checkdomain, civo, clouddns, cloudflare, cloudns, cloudru, cloudxns, conoha, constellix, corenetworks, cpanel, derak, desec, designate, digitalocean, directadmin, dnshomede, dnsimple, dnsmadeeasy, dnspod, dode, domeneshop, dreamhost, duckdns, dyn, dynu, easydns, edgedns, efficientip, epik, exec, exoscale, freemyip, gandi, gandiv5, gcloud, gcore, glesys, godaddy, googledomains, hetzner, hostingde, hosttech, httpnet, httpreq, huaweicloud, hurricane, hyperone, ibmcloud, iij, iijdpf, infoblox, infomaniak, internetbs, inwx, ionos, ipv64, iwantmyname, joker, liara, lightsail, limacity, linode, liquidweb, loopia, luadns, mailinabox, manual, metaname, mijnhost, mittwald, mydnsjp, mythicbeasts, namecheap, namedotcom, namesilo, nearlyfreespeech, netcup, netlify, nicmanager, nifcloud, njalla, nodion, ns1, oraclecloud, otc, ovh, pdns, plesk, porkbun, rackspace, rcodezero, regru, rfc2136, rimuhosting, route53, safedns, sakuracloud, scaleway, selectel, selectelv2, selfhostde, servercow, shellrent, simply, sonic, stackpath, tencentcloud, timewebcloud, transip, ultradns, variomedia, vegadns, vercel, versio, vinyldns, vkcloud, volcengine, vscale, vultr, webnames, websupport, wedos, yandex, yandex360, yandexcloud, zoneee, zonomi
145145
146146
More information: https://go-acme.github.io/lego/dns
147147
"""
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
package corenetworks
2+
3+
import (
4+
"context"
5+
"errors"
6+
"fmt"
7+
"net/http"
8+
"time"
9+
10+
"github.com/go-acme/lego/v4/challenge/dns01"
11+
"github.com/go-acme/lego/v4/platform/config/env"
12+
"github.com/go-acme/lego/v4/providers/dns/corenetworks/internal"
13+
)
14+
15+
// Environment variables names.
16+
const (
17+
envNamespace = "CORENETWORKS_"
18+
19+
EnvLogin = envNamespace + "LOGIN"
20+
EnvPassword = envNamespace + "PASSWORD"
21+
22+
EnvTTL = envNamespace + "TTL"
23+
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
24+
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
25+
EnvSequenceInterval = envNamespace + "SEQUENCE_INTERVAL"
26+
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
27+
)
28+
29+
// Config is used to configure the creation of the DNSProvider.
30+
type Config struct {
31+
Login string
32+
Password string
33+
PropagationTimeout time.Duration
34+
PollingInterval time.Duration
35+
SequenceInterval time.Duration
36+
TTL int
37+
HTTPClient *http.Client
38+
}
39+
40+
// NewDefaultConfig returns a default configuration for the DNSProvider.
41+
func NewDefaultConfig() *Config {
42+
return &Config{
43+
TTL: env.GetOrDefaultInt(EnvTTL, 3600),
44+
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
45+
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
46+
SequenceInterval: env.GetOrDefaultSecond(EnvSequenceInterval, dns01.DefaultPropagationTimeout),
47+
HTTPClient: &http.Client{
48+
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
49+
},
50+
}
51+
}
52+
53+
// DNSProvider implements the challenge.Provider interface.
54+
type DNSProvider struct {
55+
config *Config
56+
client *internal.Client
57+
}
58+
59+
// NewDNSProvider returns a DNSProvider instance configured for Core-Networks.
60+
// Credentials must be passed in the environment variables: CORENETWORKS_LOGIN, CORENETWORKS_PASSWORD.
61+
func NewDNSProvider() (*DNSProvider, error) {
62+
values, err := env.Get(EnvLogin, EnvPassword)
63+
if err != nil {
64+
return nil, fmt.Errorf("corenetworks: %w", err)
65+
}
66+
67+
config := NewDefaultConfig()
68+
config.Login = values[EnvLogin]
69+
config.Password = values[EnvPassword]
70+
71+
return NewDNSProviderConfig(config)
72+
}
73+
74+
// NewDNSProviderConfig return a DNSProvider instance configured for Bluecat DNS.
75+
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
76+
if config == nil {
77+
return nil, errors.New("corenetworks: the configuration of the DNS provider is nil")
78+
}
79+
80+
if config.Login == "" || config.Password == "" {
81+
return nil, errors.New("corenetworks: credentials missing")
82+
}
83+
84+
client := internal.NewClient(config.Login, config.Password)
85+
86+
if config.HTTPClient != nil {
87+
client.HTTPClient = config.HTTPClient
88+
}
89+
90+
return &DNSProvider{config: config, client: client}, nil
91+
}
92+
93+
// Timeout returns the timeout and interval to use when checking for DNS propagation.
94+
// Adjusting here to cope with spikes in propagation times.
95+
func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
96+
return d.config.PropagationTimeout, d.config.PollingInterval
97+
}
98+
99+
// Sequential All DNS challenges for this provider will be resolved sequentially.
100+
// Returns the interval between each iteration.
101+
func (d *DNSProvider) Sequential() time.Duration {
102+
return d.config.SequenceInterval
103+
}
104+
105+
// Present creates a TXT record using the specified parameters.
106+
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
107+
info := dns01.GetChallengeInfo(domain, keyAuth)
108+
109+
ctx, err := d.client.CreateAuthenticatedContext(context.Background())
110+
if err != nil {
111+
return fmt.Errorf("create authentication token: %w", err)
112+
}
113+
114+
zone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
115+
if err != nil {
116+
return fmt.Errorf("corenetworks: could not find zone for domain %q: %w", domain, err)
117+
}
118+
119+
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, zone)
120+
if err != nil {
121+
return fmt.Errorf("corenetworks: %w", err)
122+
}
123+
124+
record := internal.Record{
125+
Name: subDomain,
126+
TTL: d.config.TTL,
127+
Type: "TXT",
128+
Data: info.Value,
129+
}
130+
131+
err = d.client.AddRecord(ctx, dns01.UnFqdn(zone), record)
132+
if err != nil {
133+
return fmt.Errorf("corenetworks: add record: %w", err)
134+
}
135+
136+
err = d.client.CommitRecords(ctx, dns01.UnFqdn(zone))
137+
if err != nil {
138+
return fmt.Errorf("corenetworks: commit records: %w", err)
139+
}
140+
141+
return nil
142+
}
143+
144+
// CleanUp removes the TXT record matching the specified parameters.
145+
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
146+
info := dns01.GetChallengeInfo(domain, keyAuth)
147+
148+
ctx, err := d.client.CreateAuthenticatedContext(context.Background())
149+
if err != nil {
150+
return fmt.Errorf("create authentication token: %w", err)
151+
}
152+
153+
zone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
154+
if err != nil {
155+
return fmt.Errorf("corenetworks: could not find zone for domain %q: %w", domain, err)
156+
}
157+
158+
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, zone)
159+
if err != nil {
160+
return fmt.Errorf("corenetworks: %w", err)
161+
}
162+
163+
record := internal.Record{
164+
Name: subDomain,
165+
TTL: d.config.TTL,
166+
Type: "TXT",
167+
Data: info.Value,
168+
}
169+
170+
err = d.client.DeleteRecords(ctx, dns01.UnFqdn(zone), record)
171+
if err != nil {
172+
return fmt.Errorf("corenetworks: delete records: %w", err)
173+
}
174+
175+
err = d.client.CommitRecords(ctx, dns01.UnFqdn(zone))
176+
if err != nil {
177+
return fmt.Errorf("corenetworks: commit records: %w", err)
178+
}
179+
180+
return nil
181+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Name = "Core-Networks"
2+
Description = ''''''
3+
URL = "https://www.core-networks.de/"
4+
Code = "corenetworks"
5+
Since = "v4.20.0"
6+
7+
Example = '''
8+
CORENETWORKS_LOGIN="xxxx" \
9+
CORENETWORKS_PASSWORD="yyyy" \
10+
lego --email myemail@example.com --dns corenetworks --domains my.example.org run
11+
'''
12+
13+
[Configuration]
14+
[Configuration.Credentials]
15+
CORENETWORKS_LOGIN = "The username of the API account"
16+
CORENETWORKS_PASSWORD = "The password"
17+
[Configuration.Additional]
18+
CORENETWORKS_POLLING_INTERVAL = "Time between DNS propagation check"
19+
CORENETWORKS_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
20+
CORENETWORKS_TTL = "The TTL of the TXT record used for the DNS challenge"
21+
CORENETWORKS_HTTP_TIMEOUT = "API request timeout"
22+
CORENETWORKS_SEQUENCE_INTERVAL = "Time between sequential requests"
23+
24+
[Links]
25+
API = "https://beta.api.core-networks.de/doc/"

0 commit comments

Comments
 (0)