From 2faeba3482dfb69833bc03f05629d97bd09dc3fc Mon Sep 17 00:00:00 2001 From: schou Date: Wed, 6 Dec 2023 08:14:34 -0500 Subject: [PATCH 1/2] add option to register only for an eab setup Signed-off-by: schou --- cmd/cmd.go | 1 + cmd/cmd_register.go | 53 +++++++++++++++++++++++++++++++++++++++++++++ cmd/cmd_run.go | 2 +- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 cmd/cmd_register.go diff --git a/cmd/cmd.go b/cmd/cmd.go index 4d4dd3afad..d585a6c81e 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -5,6 +5,7 @@ import "github.com/urfave/cli/v2" // CreateCommands Creates all CLI commands. func CreateCommands() []*cli.Command { return []*cli.Command{ + createRegister(), createRun(), createRevoke(), createRenew(), diff --git a/cmd/cmd_register.go b/cmd/cmd_register.go new file mode 100644 index 0000000000..4673490f37 --- /dev/null +++ b/cmd/cmd_register.go @@ -0,0 +1,53 @@ +package cmd + +import ( + "fmt" + + "github.com/go-acme/lego/v4/log" + "github.com/urfave/cli/v2" +) + +func createRegister() *cli.Command { + return &cli.Command{ + Name: "register", + Usage: "Register an account", + Before: func(ctx *cli.Context) error { + // we require either domains or csr, but not both + hasDomains := len(ctx.StringSlice("domains")) > 0 + hasCsr := len(ctx.String("csr")) > 0 + if hasDomains && hasCsr { + log.Fatal("Please specify either --domains/-d or --csr/-c, but not both") + } + if !hasDomains && !hasCsr { + log.Fatal("Please specify --domains/-d (or --csr/-c if you already have a CSR)") + } + return nil + }, + Action: registerAction, + Flags: []cli.Flag{}, + } +} + +func registerAction(ctx *cli.Context) error { + accountsStorage := NewAccountsStorage(ctx) + + account, client := setup(ctx, accountsStorage) + setupChallenges(ctx, client) + + if account.Registration == nil { + reg, err := register(ctx, client) + if err != nil { + log.Fatalf("Could not complete registration\n\t%v", err) + } + + account.Registration = reg + if err = accountsStorage.Save(account); err != nil { + log.Fatal(err) + } + + fmt.Printf(rootPathWarningMessage, accountsStorage.GetRootPath()) + return err + } + + return nil +} diff --git a/cmd/cmd_run.go b/cmd/cmd_run.go index 38df4bc5cf..f10ae39074 100644 --- a/cmd/cmd_run.go +++ b/cmd/cmd_run.go @@ -17,7 +17,7 @@ import ( func createRun() *cli.Command { return &cli.Command{ Name: "run", - Usage: "Register an account, then create and install a certificate", + Usage: "Register an account (if not registered), then create and install a certificate", Before: func(ctx *cli.Context) error { // we require either domains or csr, but not both hasDomains := len(ctx.StringSlice("domains")) > 0 From 7125e6fa4c71217fce7695f960cad004f4271ebf Mon Sep 17 00:00:00 2001 From: schou Date: Wed, 6 Dec 2023 09:42:46 -0500 Subject: [PATCH 2/2] remove domain check for register Signed-off-by: schou --- cmd/cmd_register.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/cmd/cmd_register.go b/cmd/cmd_register.go index 4673490f37..f5d537ecae 100644 --- a/cmd/cmd_register.go +++ b/cmd/cmd_register.go @@ -12,15 +12,6 @@ func createRegister() *cli.Command { Name: "register", Usage: "Register an account", Before: func(ctx *cli.Context) error { - // we require either domains or csr, but not both - hasDomains := len(ctx.StringSlice("domains")) > 0 - hasCsr := len(ctx.String("csr")) > 0 - if hasDomains && hasCsr { - log.Fatal("Please specify either --domains/-d or --csr/-c, but not both") - } - if !hasDomains && !hasCsr { - log.Fatal("Please specify --domains/-d (or --csr/-c if you already have a CSR)") - } return nil }, Action: registerAction,