diff --git a/TODO.md b/TODO.md index 72061f7..89183b5 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,5 @@ # TODO -- handle cert names for wildcard domains - ## update readme - wrappers for ListenAndServeTLS diff --git a/config.go b/config.go index e1f9ffa..aaa1789 100644 --- a/config.go +++ b/config.go @@ -10,11 +10,19 @@ package simplecert import ( "errors" + "log" "os" "time" ) -var c *Config +var ( + c *Config + + errNoDirectoryURL = errors.New("simplecert: no directory url specified") + errNoMail = errors.New("simplecert: no SSLEmail in config") + errNoDomains = errors.New("simplecert: no domains specified") + errNoChallenge = errors.New("simplecert: no challenge method specified") +) // Default contains a default configuration var Default = &Config{ @@ -82,16 +90,29 @@ type Config struct { // CheckConfig checks if config can be used to obtain a cert func CheckConfig(c *Config) error { + if len(c.Domains) == 0 { - return errors.New("simplecert: no domains specified") + return errNoDomains } if !c.Local { if c.SSLEmail == "" { - return errors.New("simplecert: no SSLEmail in config") + return errNoMail } } if c.DirectoryURL == "" { - return errors.New("simplecert: no directory url specified") + return errNoDirectoryURL } + + if c.DNSProvider == "" && c.HTTPAddress == "" && c.TLSAddress == "" { + return errNoChallenge + } + + if c.WillRenewCertificate == nil && (c.HTTPAddress != "" || c.TLSAddress != "") { + log.Println("[WARNING] no WillRenewCertificate handler specified to handle graceful server shutdown") + } + if c.DidRenewCertificate == nil && (c.HTTPAddress != "" || c.TLSAddress != "") { + log.Println("[WARNING] no DidRenewCertificate handler specified to bring the service back up after renewing the certificate") + } + return nil } diff --git a/utils.go b/utils.go index 2f3db4c..eb41ba4 100644 --- a/utils.go +++ b/utils.go @@ -236,13 +236,17 @@ func renewalRoutine(cr *certificate.Resource) { time.Sleep(c.CheckInterval) // allow graceful shutdown of running services if required - c.WillRenewCertificate() + if c.WillRenewCertificate != nil { + c.WillRenewCertificate() + } // renew the certificate renew(cr) // allow service restart if required - c.DidRenewCertificate() + if c.DidRenewCertificate != nil { + c.DidRenewCertificate() + } } }