@marcel91200 / caddy Mirror · read-only / commits / 4b4e16ed
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

cmd: Ensure certmagic defaults are set for any and all subcommands

This is really crucial and I'm surprised no one reported a problem yet

Matthew Holt committed Mar 23, 2020 at 14:43 UTC 4b4e16edafd62fe0d9510987984ed26c981e84da
2 files changed +12 -10
cmd/commandfuncs.go
-10
@@ -35,7 +35,6 @@ import (
35 "github.com/caddyserver/caddy/v2"
36 "github.com/caddyserver/caddy/v2/caddyconfig"
37 "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
38 - "github.com/caddyserver/certmagic"
38 "go.uber.org/zap"
39 )
40
@@ -184,15 +183,6 @@ func cmdRun(fl Flags) (int, error) {
183 }
184 }
185
187 - // set a fitting User-Agent for ACME requests
188 - goModule := caddy.GoModule()
189 - cleanModVersion := strings.TrimPrefix(goModule.Version, "v")
190 - certmagic.UserAgent = "Caddy/" + cleanModVersion
191 -
192 - // by using Caddy, user indicates agreement to CA terms
193 - // (very important, or ACME account creation will fail!)
194 - certmagic.DefaultACME.Agreed = true
195 -
186 // run the initial config
187 err = caddy.Load(config, true)
188 if err != nil {
cmd/main.go
+12
@@ -30,9 +30,21 @@ import (
30
31 "github.com/caddyserver/caddy/v2"
32 "github.com/caddyserver/caddy/v2/caddyconfig"
33 + "github.com/caddyserver/certmagic"
34 "go.uber.org/zap"
35 )
36
37 +func init() {
38 + // set a fitting User-Agent for ACME requests
39 + goModule := caddy.GoModule()
40 + cleanModVersion := strings.TrimPrefix(goModule.Version, "v")
41 + certmagic.UserAgent = "Caddy/" + cleanModVersion
42 +
43 + // by using Caddy, user indicates agreement to CA terms
44 + // (very important, or ACME account creation will fail!)
45 + certmagic.DefaultACME.Agreed = true
46 +}
47 +
48 // Main implements the main function of the caddy command.
49 // Call this if Caddy is to be the main() if your program.
50 func Main() {