Skip to content

Commit dc824a8

Browse files
committed
review
1 parent 9cf592c commit dc824a8

File tree

12 files changed

+1010
-856
lines changed

12 files changed

+1010
-856
lines changed

cmd/zz_gen_cmd_dnshelp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func displayDNSHelp(w io.Writer, name string) error {
294294
// generated from: providers/dns/beget/beget.toml
295295
ew.writeln(`Configuration for Beget.com.`)
296296
ew.writeln(`Code: 'beget'`)
297-
ew.writeln(`Since: 'v1.0.0'`)
297+
ew.writeln(`Since: 'v4.11.0'`)
298298
ew.writeln()
299299

300300
ew.writeln(`Credentials:`)

docs/content/dns/zz_gen_beget.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ date: 2019-03-03T16:39:46+01:00
44
draft: false
55
slug: beget
66
dnsprovider:
7-
since: "v1.0.0"
7+
since: "v4.11.0"
88
code: "beget"
99
url: "https://beget.com/"
1010
---
@@ -20,7 +20,7 @@ Configuration for [Beget.com](https://beget.com/).
2020
<!--more-->
2121

2222
- Code: `beget`
23-
- Since: v1.0.0
23+
- Since: v4.11.0
2424

2525

2626
Here is an example bash command using the Beget.com provider:

providers/dns/beget/beget.go

+143-142
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,143 @@
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-
}
1+
// Package beget implements a DNS provider for solving the DNS-01 challenge using beget.com DNS.
2+
package beget
3+
4+
import (
5+
"context"
6+
"errors"
7+
"fmt"
8+
"net/http"
9+
"time"
10+
11+
"github.com/go-acme/lego/v4/challenge/dns01"
12+
"github.com/go-acme/lego/v4/platform/config/env"
13+
"github.com/go-acme/lego/v4/providers/dns/beget/internal"
14+
)
15+
16+
// Environment variables names.
17+
const (
18+
envNamespace = "BEGET_"
19+
20+
EnvUsername = envNamespace + "USERNAME"
21+
EnvPassword = envNamespace + "PASSWORD"
22+
23+
EnvTTL = envNamespace + "TTL"
24+
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
25+
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
26+
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
27+
)
28+
29+
// Config is used to configure the creation of the DNSProvider.
30+
type Config struct {
31+
Username string
32+
Password string
33+
34+
PropagationTimeout time.Duration
35+
PollingInterval 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, 300),
44+
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, dns01.DefaultPropagationTimeout*2), // 2m
45+
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, dns01.DefaultPollingInterval),
46+
HTTPClient: &http.Client{
47+
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
48+
},
49+
}
50+
}
51+
52+
// DNSProvider implements the challenge.Provider interface.
53+
type DNSProvider struct {
54+
config *Config
55+
client *internal.Client
56+
}
57+
58+
// NewDNSProvider returns a DNSProvider instance configured for beget.com.
59+
// Credentials must be passed in the environment variables:
60+
// BEGET_USERNAME and BEGET_PASSWORD.
61+
func NewDNSProvider() (*DNSProvider, error) {
62+
values, err := env.Get(EnvUsername, EnvPassword)
63+
if err != nil {
64+
return nil, fmt.Errorf("beget: %w", err)
65+
}
66+
67+
config := NewDefaultConfig()
68+
config.Username = values[EnvUsername]
69+
config.Password = values[EnvPassword]
70+
71+
return NewDNSProviderConfig(config)
72+
}
73+
74+
// NewDNSProviderConfig return a DNSProvider instance configured for beget.com.
75+
func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
76+
if config == nil {
77+
return nil, errors.New("beget: the configuration of the DNS provider is nil")
78+
}
79+
80+
if config.Username == "" || config.Password == "" {
81+
return nil, errors.New("beget: incomplete credentials, missing username and/or password")
82+
}
83+
84+
client := internal.NewClient(config.Username, 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+
// Present creates a TXT record using the specified parameters.
100+
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
101+
info := dns01.GetChallengeInfo(domain, keyAuth)
102+
103+
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
104+
if err != nil {
105+
return fmt.Errorf("beget: could not find zone for domain %q (%s): %w", domain, info.EffectiveFQDN, err)
106+
}
107+
108+
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
109+
if err != nil {
110+
return fmt.Errorf("beget: %w", err)
111+
}
112+
113+
err = d.client.AddTXTRecord(context.Background(), dns01.UnFqdn(authZone), subDomain, info.Value)
114+
if err != nil {
115+
return fmt.Errorf("beget: failed to create TXT records [domain: %s, sub domain: %s]: %w",
116+
dns01.UnFqdn(authZone), subDomain, err)
117+
}
118+
119+
return nil
120+
}
121+
122+
// CleanUp removes the TXT record matching the specified parameters.
123+
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
124+
info := dns01.GetChallengeInfo(domain, keyAuth)
125+
126+
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
127+
if err != nil {
128+
return fmt.Errorf("beget: could not find zone for domain %q (%s): %w", domain, info.EffectiveFQDN, err)
129+
}
130+
131+
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
132+
if err != nil {
133+
return fmt.Errorf("beget: %w", err)
134+
}
135+
136+
err = d.client.RemoveTxtRecord(context.Background(), dns01.UnFqdn(authZone), subDomain)
137+
if err != nil {
138+
return fmt.Errorf("beget: failed to remove TXT records [domain: %s, sub domain: %s]: %w",
139+
dns01.UnFqdn(authZone), subDomain, err)
140+
}
141+
142+
return nil
143+
}

providers/dns/beget/beget.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Name = "Beget.com"
22
Description = ''''''
33
URL = "https://beget.com/"
44
Code = "beget"
5-
Since = "v1.0.0"
5+
Since = "v4.11.0"
66

77
Example = '''
88
BEGET_USERNAME=xxxxxx \

0 commit comments

Comments
 (0)