|
1 | 1 | package cmd |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "errors" |
4 | 5 | "net" |
5 | 6 | "strings" |
6 | 7 | "time" |
@@ -38,7 +39,10 @@ func setupChallenges(ctx *cli.Context, client *lego.Client) { |
38 | 39 | } |
39 | 40 |
|
40 | 41 | if ctx.IsSet("dns") { |
41 | | - setupDNS(ctx, client) |
| 42 | + err := setupDNS(ctx, client) |
| 43 | + if err != nil { |
| 44 | + log.Fatal(err) |
| 45 | + } |
42 | 46 | } |
43 | 47 | } |
44 | 48 |
|
@@ -113,22 +117,40 @@ func setupTLSProvider(ctx *cli.Context) challenge.Provider { |
113 | 117 | } |
114 | 118 | } |
115 | 119 |
|
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 | + |
117 | 130 | provider, err := dns.NewDNSChallengeProviderByName(ctx.String("dns")) |
118 | 131 | if err != nil { |
119 | | - log.Fatal(err) |
| 132 | + return err |
120 | 133 | } |
121 | 134 |
|
122 | 135 | servers := ctx.StringSlice("dns.resolvers") |
| 136 | + |
123 | 137 | err = client.Challenge.SetDNS01Provider(provider, |
124 | 138 | dns01.CondOption(len(servers) > 0, |
125 | 139 | dns01.AddRecursiveNameservers(dns01.ParseNameservers(ctx.StringSlice("dns.resolvers")))), |
| 140 | + |
126 | 141 | dns01.CondOption(ctx.Bool("dns.disable-cp"), |
127 | 142 | 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 | + |
128 | 151 | dns01.CondOption(ctx.IsSet("dns-timeout"), |
129 | 152 | dns01.AddDNSTimeout(time.Duration(ctx.Int("dns-timeout"))*time.Second)), |
130 | 153 | ) |
131 | | - if err != nil { |
132 | | - log.Fatal(err) |
133 | | - } |
| 154 | + |
| 155 | + return err |
134 | 156 | } |
0 commit comments