Skip to content

Commit 9c87603

Browse files
authored
Add DNS provider for Regfish (#2320)
1 parent aef8970 commit 9c87603

File tree

10 files changed

+390
-9
lines changed

10 files changed

+390
-9
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,48 +184,53 @@ Detailed documentation is available [here](https://go-acme.github.io/lego/dns).
184184
</tr><tr>
185185
<td><a href="https://go-acme.github.io/lego/dns/rcodezero/">RcodeZero</a></td>
186186
<td><a href="https://go-acme.github.io/lego/dns/regru/">reg.ru</a></td>
187+
<td><a href="https://go-acme.github.io/lego/dns/regfish/">Regfish</a></td>
187188
<td><a href="https://go-acme.github.io/lego/dns/rfc2136/">RFC2136</a></td>
188-
<td><a href="https://go-acme.github.io/lego/dns/rimuhosting/">RimuHosting</a></td>
189189
</tr><tr>
190+
<td><a href="https://go-acme.github.io/lego/dns/rimuhosting/">RimuHosting</a></td>
190191
<td><a href="https://go-acme.github.io/lego/dns/sakuracloud/">Sakura Cloud</a></td>
191192
<td><a href="https://go-acme.github.io/lego/dns/scaleway/">Scaleway</a></td>
192193
<td><a href="https://go-acme.github.io/lego/dns/selectel/">Selectel</a></td>
193-
<td><a href="https://go-acme.github.io/lego/dns/selectelv2/">Selectel v2</a></td>
194194
</tr><tr>
195+
<td><a href="https://go-acme.github.io/lego/dns/selectelv2/">Selectel v2</a></td>
195196
<td><a href="https://go-acme.github.io/lego/dns/selfhostde/">SelfHost.(de|eu)</a></td>
196197
<td><a href="https://go-acme.github.io/lego/dns/servercow/">Servercow</a></td>
197198
<td><a href="https://go-acme.github.io/lego/dns/shellrent/">Shellrent</a></td>
198-
<td><a href="https://go-acme.github.io/lego/dns/simply/">Simply.com</a></td>
199199
</tr><tr>
200+
<td><a href="https://go-acme.github.io/lego/dns/simply/">Simply.com</a></td>
200201
<td><a href="https://go-acme.github.io/lego/dns/sonic/">Sonic</a></td>
201202
<td><a href="https://go-acme.github.io/lego/dns/stackpath/">Stackpath</a></td>
202203
<td><a href="https://go-acme.github.io/lego/dns/tencentcloud/">Tencent Cloud DNS</a></td>
203-
<td><a href="https://go-acme.github.io/lego/dns/timewebcloud/">Timeweb Cloud</a></td>
204204
</tr><tr>
205+
<td><a href="https://go-acme.github.io/lego/dns/timewebcloud/">Timeweb Cloud</a></td>
205206
<td><a href="https://go-acme.github.io/lego/dns/transip/">TransIP</a></td>
206207
<td><a href="https://go-acme.github.io/lego/dns/safedns/">UKFast SafeDNS</a></td>
207208
<td><a href="https://go-acme.github.io/lego/dns/ultradns/">Ultradns</a></td>
208-
<td><a href="https://go-acme.github.io/lego/dns/variomedia/">Variomedia</a></td>
209209
</tr><tr>
210+
<td><a href="https://go-acme.github.io/lego/dns/variomedia/">Variomedia</a></td>
210211
<td><a href="https://go-acme.github.io/lego/dns/vegadns/">VegaDNS</a></td>
211212
<td><a href="https://go-acme.github.io/lego/dns/vercel/">Vercel</a></td>
212213
<td><a href="https://go-acme.github.io/lego/dns/versio/">Versio.[nl|eu|uk]</a></td>
213-
<td><a href="https://go-acme.github.io/lego/dns/vinyldns/">VinylDNS</a></td>
214214
</tr><tr>
215+
<td><a href="https://go-acme.github.io/lego/dns/vinyldns/">VinylDNS</a></td>
215216
<td><a href="https://go-acme.github.io/lego/dns/vkcloud/">VK Cloud</a></td>
216217
<td><a href="https://go-acme.github.io/lego/dns/volcengine/">Volcano Engine/火山引擎</a></td>
217218
<td><a href="https://go-acme.github.io/lego/dns/vscale/">Vscale</a></td>
218-
<td><a href="https://go-acme.github.io/lego/dns/vultr/">Vultr</a></td>
219219
</tr><tr>
220+
<td><a href="https://go-acme.github.io/lego/dns/vultr/">Vultr</a></td>
220221
<td><a href="https://go-acme.github.io/lego/dns/webnames/">Webnames</a></td>
221222
<td><a href="https://go-acme.github.io/lego/dns/websupport/">Websupport</a></td>
222223
<td><a href="https://go-acme.github.io/lego/dns/wedos/">WEDOS</a></td>
223-
<td><a href="https://go-acme.github.io/lego/dns/yandex360/">Yandex 360</a></td>
224224
</tr><tr>
225+
<td><a href="https://go-acme.github.io/lego/dns/yandex360/">Yandex 360</a></td>
225226
<td><a href="https://go-acme.github.io/lego/dns/yandexcloud/">Yandex Cloud</a></td>
226227
<td><a href="https://go-acme.github.io/lego/dns/yandex/">Yandex PDD</a></td>
227228
<td><a href="https://go-acme.github.io/lego/dns/zoneee/">Zone.ee</a></td>
229+
</tr><tr>
228230
<td><a href="https://go-acme.github.io/lego/dns/zonomi/">Zonomi</a></td>
231+
<td></td>
232+
<td></td>
233+
<td></td>
229234
</tr></table>
230235

231236
<!-- END DNS PROVIDERS LIST -->

cmd/zz_gen_cmd_dnshelp.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/dns/zz_gen_regfish.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: "Regfish"
3+
date: 2019-03-03T16:39:46+01:00
4+
draft: false
5+
slug: regfish
6+
dnsprovider:
7+
since: "v4.20.0"
8+
code: "regfish"
9+
url: "https://regfish.de/"
10+
---
11+
12+
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
13+
<!-- providers/dns/regfish/regfish.toml -->
14+
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
15+
16+
17+
Configuration for [Regfish](https://regfish.de/).
18+
19+
20+
<!--more-->
21+
22+
- Code: `regfish`
23+
- Since: v4.20.0
24+
25+
26+
Here is an example bash command using the Regfish provider:
27+
28+
```bash
29+
REGFISH_API_KEY="xxxxxxxxxxxxxxxxxxxxx" \
30+
lego --email [email protected] --dns regfish --domains my.example.org run
31+
```
32+
33+
34+
35+
36+
## Credentials
37+
38+
| Environment Variable Name | Description |
39+
|-----------------------|-------------|
40+
| `REGFISH_API_KEY` | API key |
41+
42+
The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
43+
More information [here]({{% ref "dns#configuration-and-credentials" %}}).
44+
45+
46+
## Additional Configuration
47+
48+
| Environment Variable Name | Description |
49+
|--------------------------------|-------------|
50+
| `REGFISH_HTTP_TIMEOUT` | API request timeout |
51+
| `REGFISH_POLLING_INTERVAL` | Time between DNS propagation check |
52+
| `REGFISH_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
53+
| `REGFISH_TTL` | The TTL of the TXT record used for the DNS challenge |
54+
55+
The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
56+
More information [here]({{% ref "dns#configuration-and-credentials" %}}).
57+
58+
59+
60+
61+
## More information
62+
63+
- [API documentation](https://regfish.readme.io/)
64+
- [Go client](https://github.com/regfish/regfish-dnsapi-go)
65+
66+
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
67+
<!-- providers/dns/regfish/regfish.toml -->
68+
<!-- 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, 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
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, regfish, 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
"""

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ require (
6262
github.com/ovh/go-ovh v1.6.0
6363
github.com/pquerna/otp v1.4.0
6464
github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2
65+
github.com/regfish/regfish-dnsapi-go v0.1.1
6566
github.com/sacloud/api-client-go v0.2.10
6667
github.com/sacloud/iaas-api-go v1.12.0
6768
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.30

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y
494494
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
495495
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
496496
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
497+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
498+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
497499
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
498500
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
499501
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
@@ -731,6 +733,8 @@ github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2 h1:dq90+d51/hQR
731733
github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2/go.mod h1:7tZKcyumwBO6qip7RNQ5r77yrssm9bfCowcLEBcU5IA=
732734
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
733735
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
736+
github.com/regfish/regfish-dnsapi-go v0.1.1 h1:TJFtbePHkd47q5GZwYl1h3DIYXmoxdLjW/SBsPtB5IE=
737+
github.com/regfish/regfish-dnsapi-go v0.1.1/go.mod h1:ubIgXSfqarSnl3XHSn8hIFwFF3h0yrq0ZiWD93Y2VjY=
734738
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
735739
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
736740
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=

providers/dns/regfish/regfish.go

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// Package regfish implements a DNS provider for solving the DNS-01 challenge using Regfish.
2+
package regfish
3+
4+
import (
5+
"errors"
6+
"fmt"
7+
"net/http"
8+
"sync"
9+
"time"
10+
11+
"github.com/go-acme/lego/v4/challenge/dns01"
12+
"github.com/go-acme/lego/v4/platform/config/env"
13+
regfishapi "github.com/regfish/regfish-dnsapi-go"
14+
)
15+
16+
// Environment variables names.
17+
const (
18+
envNamespace = "REGFISH_"
19+
20+
EnvAPIKey = envNamespace + "API_KEY"
21+
22+
EnvTTL = envNamespace + "TTL"
23+
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
24+
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
25+
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
26+
)
27+
28+
// Config is used to configure the creation of the DNSProvider.
29+
type Config struct {
30+
APIKey string
31+
32+
PropagationTimeout time.Duration
33+
PollingInterval time.Duration
34+
TTL int
35+
HTTPClient *http.Client
36+
}
37+
38+
// NewDefaultConfig returns a default configuration for the DNSProvider.
39+
func NewDefaultConfig() *Config {
40+
return &Config{
41+
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
42+
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout),
43+
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
44+
HTTPClient: &http.Client{
45+
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
46+
},
47+
}
48+
}
49+
50+
// DNSProvider implements the challenge.Provider interface.
51+
type DNSProvider struct {
52+
config *Config
53+
client *regfishapi.Client
54+
55+
recordIDs map[string]int
56+
recordIDsMu sync.Mutex
57+
}
58+
59+
// NewDNSProvider returns a DNSProvider instance configured for Regfish.
60+
func NewDNSProvider() (*DNSProvider, error) {
61+
values, err := env.Get(EnvAPIKey)
62+
if err != nil {
63+
return nil, fmt.Errorf("regfish: %w", err)
64+
}
65+
66+
config := NewDefaultConfig()
67+
config.APIKey = values[EnvAPIKey]
68+
69+
return NewDNSProviderConfig(config)
70+
}
71+
72+
// NewDNSProviderConfig return a DNSProvider instance configured for Regfish.
73+
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
74+
if config == nil {
75+
return nil, errors.New("regfish: the configuration of the DNS provider is nil")
76+
}
77+
78+
if config.APIKey == "" {
79+
return nil, errors.New("regfish: credentials missing")
80+
}
81+
82+
client := regfishapi.NewClient(config.APIKey)
83+
84+
return &DNSProvider{
85+
config: config,
86+
client: client,
87+
recordIDs: make(map[string]int),
88+
}, nil
89+
}
90+
91+
// Present creates a TXT record using the specified parameters.
92+
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
93+
info := dns01.GetChallengeInfo(domain, keyAuth)
94+
95+
record := regfishapi.Record{
96+
Name: info.EffectiveFQDN,
97+
Type: "TXT",
98+
Data: info.Value,
99+
TTL: d.config.TTL,
100+
}
101+
102+
newRecord, err := d.client.CreateRecord(record)
103+
if err != nil {
104+
return fmt.Errorf("regfish: create record: %w", err)
105+
}
106+
107+
d.recordIDsMu.Lock()
108+
d.recordIDs[token] = newRecord.ID
109+
d.recordIDsMu.Unlock()
110+
111+
return nil
112+
}
113+
114+
// CleanUp removes the TXT record matching the specified parameters.
115+
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
116+
info := dns01.GetChallengeInfo(domain, keyAuth)
117+
118+
// get the record's unique ID from when we created it
119+
d.recordIDsMu.Lock()
120+
recordID, ok := d.recordIDs[token]
121+
d.recordIDsMu.Unlock()
122+
if !ok {
123+
return fmt.Errorf("regfish: unknown record ID for '%s'", info.EffectiveFQDN)
124+
}
125+
126+
err := d.client.DeleteRecord(recordID)
127+
if err != nil {
128+
return fmt.Errorf("regfish: delete record: %w", err)
129+
}
130+
131+
// Delete record ID from map
132+
d.recordIDsMu.Lock()
133+
delete(d.recordIDs, token)
134+
d.recordIDsMu.Unlock()
135+
136+
return nil
137+
}
138+
139+
// Timeout returns the timeout and interval to use when checking for DNS propagation.
140+
// Adjusting here to cope with spikes in propagation times.
141+
func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
142+
return d.config.PropagationTimeout, d.config.PollingInterval
143+
}

providers/dns/regfish/regfish.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Name = "Regfish"
2+
Description = ''''''
3+
URL = "https://regfish.de/"
4+
Code = "regfish"
5+
Since = "v4.20.0"
6+
7+
Example = '''
8+
REGFISH_API_KEY="xxxxxxxxxxxxxxxxxxxxx" \
9+
lego --email [email protected] --dns regfish --domains my.example.org run
10+
'''
11+
12+
[Configuration]
13+
[Configuration.Credentials]
14+
REGFISH_API_KEY = "API key"
15+
[Configuration.Additional]
16+
REGFISH_POLLING_INTERVAL = "Time between DNS propagation check"
17+
REGFISH_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
18+
REGFISH_TTL = "The TTL of the TXT record used for the DNS challenge"
19+
REGFISH_HTTP_TIMEOUT = "API request timeout"
20+
21+
[Links]
22+
API = "https://regfish.readme.io/"
23+
GoClient = "https://github.com/regfish/regfish-dnsapi-go"

0 commit comments

Comments
 (0)