Skip to content

Commit 75b910b

Browse files
authored
feat(cli): add dns.propagation-wait flag (#2266)
1 parent b3e6307 commit 75b910b

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

cmd/flags.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ func CreateFlags(defaultPath string) []cli.Flag {
113113
Name: "dns.disable-cp",
114114
Usage: "By setting this flag to true, disables the need to await propagation of the TXT record to all authoritative name servers.",
115115
},
116+
&cli.DurationFlag{
117+
Name: "dns.propagation-wait",
118+
Usage: "By setting this flag, disables all the propagation checks and uses a wait duration instead.",
119+
},
116120
&cli.StringSliceFlag{
117121
Name: "dns.resolvers",
118122
Usage: "Set the resolvers to use for performing (recursive) CNAME resolving and apex domain determination." +

cmd/setup_challenges.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"errors"
45
"net"
56
"strings"
67
"time"
@@ -38,7 +39,10 @@ func setupChallenges(ctx *cli.Context, client *lego.Client) {
3839
}
3940

4041
if ctx.IsSet("dns") {
41-
setupDNS(ctx, client)
42+
err := setupDNS(ctx, client)
43+
if err != nil {
44+
log.Fatal(err)
45+
}
4246
}
4347
}
4448

@@ -113,22 +117,40 @@ func setupTLSProvider(ctx *cli.Context) challenge.Provider {
113117
}
114118
}
115119

116-
func setupDNS(ctx *cli.Context, client *lego.Client) {
120+
func setupDNS(ctx *cli.Context, client *lego.Client) error {
121+
if ctx.IsSet("dns.disable-cp") && ctx.Bool("dns.disable-cp") && ctx.IsSet("dns.propagation-wait") {
122+
return errors.New("'dns.disable-cp' and 'dns.propagation-wait' are mutually exclusive")
123+
}
124+
125+
wait := ctx.Duration("dns.propagation-wait")
126+
if wait < 0 {
127+
return errors.New("'dns.propagation-wait' cannot be negative")
128+
}
129+
117130
provider, err := dns.NewDNSChallengeProviderByName(ctx.String("dns"))
118131
if err != nil {
119-
log.Fatal(err)
132+
return err
120133
}
121134

122135
servers := ctx.StringSlice("dns.resolvers")
136+
123137
err = client.Challenge.SetDNS01Provider(provider,
124138
dns01.CondOption(len(servers) > 0,
125139
dns01.AddRecursiveNameservers(dns01.ParseNameservers(ctx.StringSlice("dns.resolvers")))),
140+
126141
dns01.CondOption(ctx.Bool("dns.disable-cp"),
127142
dns01.DisableCompletePropagationRequirement()),
143+
144+
dns01.CondOption(ctx.IsSet("dns.propagation-wait"), dns01.WrapPreCheck(
145+
func(domain, fqdn, value string, check dns01.PreCheckFunc) (bool, error) {
146+
time.Sleep(wait)
147+
return true, nil
148+
},
149+
)),
150+
128151
dns01.CondOption(ctx.IsSet("dns-timeout"),
129152
dns01.AddDNSTimeout(time.Duration(ctx.Int("dns-timeout"))*time.Second)),
130153
)
131-
if err != nil {
132-
log.Fatal(err)
133-
}
154+
155+
return err
134156
}

docs/data/zz_cli_help.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ GLOBAL OPTIONS:
4040
--tls.port value Set the port and interface to use for TLS-ALPN-01 based challenges to listen on. Supported: interface:port or :port. (default: ":443")
4141
--dns value Solve a DNS-01 challenge using the specified provider. Can be mixed with other types of challenges. Run 'lego dnshelp' for help on usage.
4242
--dns.disable-cp By setting this flag to true, disables the need to await propagation of the TXT record to all authoritative name servers. (default: false)
43+
--dns.propagation-wait value By setting this flag, disables all the propagation checks and uses a wait duration instead. (default: 0s)
4344
--dns.resolvers value [ --dns.resolvers value ] Set the resolvers to use for performing (recursive) CNAME resolving and apex domain determination. For DNS-01 challenge verification, the authoritative DNS server is queried directly. Supported: host:port. The default is to use the system resolvers, or Google's DNS resolvers if the system's cannot be determined.
4445
--http-timeout value Set the HTTP timeout value to a specific value in seconds. (default: 0)
4546
--dns-timeout value Set the DNS timeout value to a specific value in seconds. Used only when performing authoritative name server queries. (default: 10)

0 commit comments

Comments
 (0)