Skip to content

Commit 61bbd39

Browse files
icfif31ldez
authored andcommitted
Add Beget.com as DNS provider
1 parent d6c1ed9 commit 61bbd39

File tree

10 files changed

+638
-34
lines changed

10 files changed

+638
-34
lines changed

README.md

+33-33
Large diffs are not rendered by default.

cmd/zz_gen_cmd_dnshelp.go

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/dns/zz_gen_beget.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: "Beget.com"
3+
date: 2019-03-03T16:39:46+01:00
4+
draft: false
5+
slug: beget
6+
dnsprovider:
7+
since: "v1.0.0"
8+
code: "beget"
9+
url: "https://beget.com/"
10+
---
11+
12+
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
13+
<!-- providers/dns/beget/beget.toml -->
14+
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
15+
16+
17+
Configuration for [Beget.com](https://beget.com/).
18+
19+
20+
<!--more-->
21+
22+
- Code: `beget`
23+
- Since: v1.0.0
24+
25+
26+
Here is an example bash command using the Beget.com provider:
27+
28+
```bash
29+
BEGET_USERNAME=xxxxxx \
30+
BEGET_PASSWORD=yyyyyy \
31+
lego --email [email protected] --dns beget --domains my.example.org run
32+
```
33+
34+
35+
36+
37+
## Credentials
38+
39+
| Environment Variable Name | Description |
40+
|-----------------------|-------------|
41+
| `BEGET_PASSWORD` | API password |
42+
| `BEGET_USERNAME` | API username |
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+
| `BEGET_HTTP_TIMEOUT` | API request timeout |
53+
| `BEGET_POLLING_INTERVAL` | Time between DNS propagation check |
54+
| `BEGET_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
55+
| `BEGET_TTL` | The TTL of the TXT record used for the DNS challenge |
56+
57+
The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.
58+
More information [here]({{% ref "dns#configuration-and-credentials" %}}).
59+
60+
61+
62+
63+
## More information
64+
65+
- [API documentation](https://beget.com/ru/kb/api/funkczii-upravleniya-dns)
66+
67+
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
68+
<!-- providers/dns/beget/beget.toml -->
69+
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->

docs/data/zz_cli_help.toml

+1-1
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, beget, 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
145145
146146
More information: https://go-acme.github.io/lego/dns
147147
"""

providers/dns/beget/beget.go

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Package beget implements a DNS provider for solving the DNS-01 challenge using beget.com DNS.
2+
package beget
3+
4+
import (
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/beget/internal"
13+
)
14+
15+
// Environment variables names.
16+
const (
17+
envNamespace = "BEGET_"
18+
19+
EnvUsername = envNamespace + "USERNAME"
20+
EnvPassword = envNamespace + "PASSWORD"
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+
Username string
31+
Password string
32+
33+
PropagationTimeout time.Duration
34+
PollingInterval time.Duration
35+
TTL int
36+
HTTPClient *http.Client
37+
}
38+
39+
// NewDefaultConfig returns a default configuration for the DNSProvider.
40+
func NewDefaultConfig() *Config {
41+
return &Config{
42+
TTL: env.GetOrDefaultInt(EnvTTL, 300),
43+
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout*2), //2m
44+
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
45+
HTTPClient: &http.Client{
46+
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
47+
},
48+
}
49+
}
50+
51+
// DNSProvider implements the challenge.Provider interface.
52+
type DNSProvider struct {
53+
config *Config
54+
client *internal.Client
55+
}
56+
57+
// NewDNSProvider returns a DNSProvider instance configured for beget.com.
58+
// Credentials must be passed in the environment variables:
59+
// BEGET_USERNAME and BEGET_PASSWORD.
60+
func NewDNSProvider() (*DNSProvider, error) {
61+
values, err := env.Get(EnvUsername, EnvPassword)
62+
if err != nil {
63+
return nil, fmt.Errorf("beget: %w", err)
64+
}
65+
66+
config := NewDefaultConfig()
67+
config.Username = values[EnvUsername]
68+
config.Password = values[EnvPassword]
69+
70+
return NewDNSProviderConfig(config)
71+
}
72+
73+
// NewDNSProviderConfig return a DNSProvider instance configured for beget.com.
74+
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
75+
if config == nil {
76+
return nil, errors.New("beget: the configuration of the DNS provider is nil")
77+
}
78+
79+
if config.Username == "" || config.Password == "" {
80+
return nil, errors.New("beget: incomplete credentials, missing username and/or password")
81+
}
82+
83+
client := internal.NewClient(config.Username, config.Password)
84+
85+
if config.HTTPClient != nil {
86+
client.HTTPClient = config.HTTPClient
87+
}
88+
89+
return &DNSProvider{config: config, client: client}, nil
90+
}
91+
92+
// Timeout returns the timeout and interval to use when checking for DNS propagation.
93+
// Adjusting here to cope with spikes in propagation times.
94+
func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
95+
return d.config.PropagationTimeout, d.config.PollingInterval
96+
}
97+
98+
// Present creates a TXT record using the specified parameters.
99+
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
100+
info := dns01.GetChallengeInfo(domain, keyAuth)
101+
102+
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
103+
if err != nil {
104+
return fmt.Errorf("beget: could not find zone for domain %q and fqdn %q : %w", domain, info.EffectiveFQDN, err)
105+
}
106+
107+
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
108+
if err != nil {
109+
return fmt.Errorf("beget: %w", err)
110+
}
111+
112+
err = d.client.AddTXTRecord(dns01.UnFqdn(authZone), subDomain, info.Value)
113+
if err != nil {
114+
return fmt.Errorf("beget: failed to create TXT records [domain: %s, sub domain: %s]: %w",
115+
dns01.UnFqdn(authZone), subDomain, err)
116+
}
117+
118+
return nil
119+
}
120+
121+
// CleanUp removes the TXT record matching the specified parameters.
122+
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
123+
info := dns01.GetChallengeInfo(domain, keyAuth)
124+
125+
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
126+
if err != nil {
127+
return fmt.Errorf("beget: could not find zone for domain %q and fqdn %q : %w", domain, info.EffectiveFQDN, err)
128+
}
129+
130+
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
131+
if err != nil {
132+
return fmt.Errorf("beget: %w", err)
133+
}
134+
135+
err = d.client.RemoveTxtRecord(dns01.UnFqdn(authZone), subDomain)
136+
if err != nil {
137+
return fmt.Errorf("beget: failed to remove TXT records [domain: %s, sub domain: %s]: %w",
138+
dns01.UnFqdn(authZone), subDomain, err)
139+
}
140+
141+
return nil
142+
}

providers/dns/beget/beget.toml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Name = "Beget.com"
2+
Description = ''''''
3+
URL = "https://beget.com/"
4+
Code = "beget"
5+
Since = "v1.0.0"
6+
7+
Example = '''
8+
BEGET_USERNAME=xxxxxx \
9+
BEGET_PASSWORD=yyyyyy \
10+
lego --email [email protected] --dns beget --domains my.example.org run
11+
'''
12+
13+
[Configuration]
14+
[Configuration.Credentials]
15+
BEGET_USERNAME = "API username"
16+
BEGET_PASSWORD = "API password"
17+
[Configuration.Additional]
18+
BEGET_POLLING_INTERVAL = "Time between DNS propagation check"
19+
BEGET_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
20+
BEGET_TTL = "The TTL of the TXT record used for the DNS challenge"
21+
BEGET_HTTP_TIMEOUT = "API request timeout"
22+
23+
[Links]
24+
API = "https://beget.com/ru/kb/api/funkczii-upravleniya-dns"

0 commit comments

Comments
 (0)