summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-03-23 14:43:42 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2020-03-23 14:43:42 -0600
commit4b4e16edafd62fe0d9510987984ed26c981e84da (patch)
treeacb3000fa0dc72d37c20b6332737b7dcc4a1edeb
parentee64719d932284419b5267b2eb94f9fc3a0d516b (diff)
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
-rw-r--r--cmd/commandfuncs.go10
-rw-r--r--cmd/main.go12
2 files changed, 12 insertions, 10 deletions
diff --git a/cmd/commandfuncs.go b/cmd/commandfuncs.go
index 80d00a3..46de9de 100644
--- a/cmd/commandfuncs.go
+++ b/cmd/commandfuncs.go
@@ -35,7 +35,6 @@ import (
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
- "github.com/caddyserver/certmagic"
"go.uber.org/zap"
)
@@ -184,15 +183,6 @@ func cmdRun(fl Flags) (int, error) {
}
}
- // set a fitting User-Agent for ACME requests
- goModule := caddy.GoModule()
- cleanModVersion := strings.TrimPrefix(goModule.Version, "v")
- certmagic.UserAgent = "Caddy/" + cleanModVersion
-
- // by using Caddy, user indicates agreement to CA terms
- // (very important, or ACME account creation will fail!)
- certmagic.DefaultACME.Agreed = true
-
// run the initial config
err = caddy.Load(config, true)
if err != nil {
diff --git a/cmd/main.go b/cmd/main.go
index 4dbbe38..bdc95a4 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -30,9 +30,21 @@ import (
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig"
+ "github.com/caddyserver/certmagic"
"go.uber.org/zap"
)
+func init() {
+ // set a fitting User-Agent for ACME requests
+ goModule := caddy.GoModule()
+ cleanModVersion := strings.TrimPrefix(goModule.Version, "v")
+ certmagic.UserAgent = "Caddy/" + cleanModVersion
+
+ // by using Caddy, user indicates agreement to CA terms
+ // (very important, or ACME account creation will fail!)
+ certmagic.DefaultACME.Agreed = true
+}
+
// Main implements the main function of the caddy command.
// Call this if Caddy is to be the main() if your program.
func Main() {