1515package certmagic
1616
1717import (
18- "errors"
1918 "fmt"
2019 "log"
2120 "net"
@@ -95,6 +94,8 @@ func (cfg *Config) newACMEClient(interactive bool) (*acmeClient, error) {
9594 legoCfg := lego .NewConfig (& leUser )
9695 legoCfg .CADirURL = caURL
9796 legoCfg .KeyType = keyType
97+ legoCfg .UserAgent = UserAgent
98+ legoCfg .HTTPClient .Timeout = HTTPTimeout
9899 client , err = lego .NewClient (legoCfg )
99100 if err != nil {
100101 cfg .acmeClientsMu .Unlock ()
@@ -113,7 +114,7 @@ func (cfg *Config) newACMEClient(interactive bool) (*acmeClient, error) {
113114 cfg .Agreed = cfg .askUserAgreement (client .GetToSURL ())
114115 }
115116 if ! cfg .Agreed && termsURL != "" {
116- return nil , errors . New ("user must agree to CA terms (use -agree flag) " )
117+ return nil , fmt . Errorf ("user must agree to CA terms" )
117118 }
118119 }
119120
@@ -126,7 +127,7 @@ func (cfg *Config) newACMEClient(interactive bool) (*acmeClient, error) {
126127 // persist the user to storage
127128 err = cfg .saveUser (leUser )
128129 if err != nil {
129- return nil , errors . New ("could not save user: " + err . Error () )
130+ return nil , fmt . Errorf ("could not save user: %v" , err )
130131 }
131132 }
132133
@@ -249,7 +250,7 @@ func (c *acmeClient) Obtain(name string) error {
249250
250251 // double-check that we actually got a certificate, in case there's a bug upstream (see issue mholt/caddy#2121)
251252 if certificate .Domain == "" || certificate .Certificate == nil {
252- return errors . New ("returned certificate was empty; probably an unchecked error obtaining it" )
253+ return fmt . Errorf ("returned certificate was empty; probably an unchecked error obtaining it" )
253254 }
254255
255256 // Success - immediately save the certificate resource
@@ -309,7 +310,7 @@ func (c *acmeClient) Renew(name string) error {
309310 if err == nil {
310311 // double-check that we actually got a certificate; check a couple fields, just in case
311312 if newCertMeta == nil || newCertMeta .Domain == "" || newCertMeta .Certificate == nil {
312- err = errors . New ("returned certificate was empty; probably an unchecked error renewing it" )
313+ err = fmt . Errorf ("returned certificate was empty; probably an unchecked error renewing it" )
313314 } else {
314315 success = true
315316 break
@@ -323,7 +324,7 @@ func (c *acmeClient) Renew(name string) error {
323324 }
324325
325326 if ! success {
326- return errors . New ("too many renewal attempts; last error: " + err . Error () )
327+ return fmt . Errorf ("too many renewal attempts; last error: %v" , err )
327328 }
328329
329330 if c .config .OnEvent != nil {
@@ -369,3 +370,9 @@ func (c *acmeClient) Revoke(name string) error {
369370
370371 return nil
371372}
373+
374+ // Some default values passed down to the underlying lego client.
375+ var (
376+ UserAgent string
377+ HTTPTimeout = 30 * time .Second
378+ )
0 commit comments