diff --git a/cmd/cmd_renew.go b/cmd/cmd_renew.go index c28a58847..d9d9293b3 100644 --- a/cmd/cmd_renew.go +++ b/cmd/cmd_renew.go @@ -25,17 +25,6 @@ import ( "github.com/urfave/cli/v3" ) -// Flag names. -const ( - flgRenewDays = "days" - flgRenewDynamic = "dynamic" - flgARIDisable = "ari-disable" - flgARIWaitToRenewDuration = "ari-wait-to-renew-duration" - flgReuseKey = "reuse-key" - flgNoRandomSleep = "no-random-sleep" - flgForceCertDomains = "force-cert-domains" -) - func createRenew() *cli.Command { return &cli.Command{ Name: "renew", @@ -64,51 +53,6 @@ func createRenew() *cli.Command { } } -func createRenewFlags() []cli.Flag { - flags := CreateBaseFlags() - - flags = append(flags, CreateChallengesFlags()...) - flags = append(flags, CreateObtainFlags()...) - flags = append(flags, CreateHookFlags(flgRenewHook, flgRenewHookTimeout)...) - - flags = append(flags, - &cli.IntFlag{ - Name: flgRenewDays, - Value: 30, - Usage: "The number of days left on a certificate to renew it.", - }, - // TODO(ldez): in v5, remove this flag, use this behavior as default. - &cli.BoolFlag{ - Name: flgRenewDynamic, - Value: false, - Usage: "Compute dynamically, based on the lifetime of the certificate(s), when to renew: use 1/3rd of the lifetime left, or 1/2 of the lifetime for short-lived certificates). This supersedes --days and will be the default behavior in Lego v5.", - }, - &cli.BoolFlag{ - Name: flgARIDisable, - Usage: "Do not use the renewalInfo endpoint (RFC9773) to check if a certificate should be renewed.", - }, - &cli.DurationFlag{ - Name: flgARIWaitToRenewDuration, - Usage: "The maximum duration you're willing to sleep for a renewal time returned by the renewalInfo endpoint.", - }, - &cli.BoolFlag{ - Name: flgReuseKey, - Usage: "Used to indicate you want to reuse your current private key for the new certificate.", - }, - &cli.BoolFlag{ - Name: flgNoRandomSleep, - Usage: "Do not add a random sleep before the renewal." + - " We do not recommend using this flag if you are doing your renewals in an automated way.", - }, - &cli.BoolFlag{ - Name: flgForceCertDomains, - Usage: "Check and ensure that the cert's domain list matches those passed in the domains argument.", - }, - ) - - return flags -} - func renew(ctx context.Context, cmd *cli.Command) error { account, keyType := setupAccount(ctx, cmd, newAccountsStorage(cmd)) diff --git a/cmd/cmd_run.go b/cmd/cmd_run.go index 316176a91..18751990b 100644 --- a/cmd/cmd_run.go +++ b/cmd/cmd_run.go @@ -17,10 +17,16 @@ import ( "github.com/urfave/cli/v3" ) -// Flag names. -const ( - flgPrivateKey = "private-key" -) +const rootPathWarningMessage = `!!!! HEADS UP !!!! + +Your account credentials have been saved in your +configuration directory at "%s". + +You should make a secure backup of this folder now. This +configuration directory will also contain private keys +generated by lego and certificates obtained from the ACME +server. Making regular backups of this folder is ideal. +` func createRun() *cli.Command { return &cli.Command{ @@ -46,34 +52,6 @@ func createRun() *cli.Command { } } -func createRunFlags() []cli.Flag { - flags := CreateBaseFlags() - - flags = append(flags, CreateChallengesFlags()...) - flags = append(flags, CreateObtainFlags()...) - flags = append(flags, CreateHookFlags(flgRunHook, flgRunHookTimeout)...) - - flags = append(flags, - &cli.StringFlag{ - Name: flgPrivateKey, - Usage: "Path to private key (in PEM encoding) for the certificate. By default, the private key is generated.", - }, - ) - - return flags -} - -const rootPathWarningMessage = `!!!! HEADS UP !!!! - -Your account credentials have been saved in your -configuration directory at "%s". - -You should make a secure backup of this folder now. This -configuration directory will also contain private keys -generated by lego and certificates obtained from the ACME -server. Making regular backups of this folder is ideal. -` - func run(ctx context.Context, cmd *cli.Command) error { accountsStorage := newAccountsStorage(cmd) diff --git a/cmd/flags.go b/cmd/flags.go index fda783d74..f8afa2d61 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -95,6 +95,22 @@ const ( flgRunHookTimeout = "run-hook-timeout" ) +// Flag names related to the specific run command. +const ( + flgPrivateKey = "private-key" +) + +// Flag names related to the specific renew command. +const ( + flgRenewDays = "days" + flgRenewDynamic = "dynamic" + flgARIDisable = "ari-disable" + flgARIWaitToRenewDuration = "ari-wait-to-renew-duration" + flgReuseKey = "reuse-key" + flgNoRandomSleep = "no-random-sleep" + flgForceCertDomains = "force-cert-domains" +) + // Environment variable names. const ( envEAB = "LEGO_EAB" @@ -389,6 +405,68 @@ func CreateBaseFlags() []cli.Flag { return flags } +func createRunFlags() []cli.Flag { + flags := CreateBaseFlags() + + flags = append(flags, CreateChallengesFlags()...) + flags = append(flags, CreateObtainFlags()...) + flags = append(flags, CreateHookFlags(flgRunHook, flgRunHookTimeout)...) + + flags = append(flags, + &cli.StringFlag{ + Name: flgPrivateKey, + Usage: "Path to private key (in PEM encoding) for the certificate. By default, the private key is generated.", + }, + ) + + return flags +} + +func createRenewFlags() []cli.Flag { + flags := CreateBaseFlags() + + flags = append(flags, CreateChallengesFlags()...) + flags = append(flags, CreateObtainFlags()...) + flags = append(flags, CreateHookFlags(flgRenewHook, flgRenewHookTimeout)...) + + flags = append(flags, + &cli.IntFlag{ + Name: flgRenewDays, + Value: 30, + Usage: "The number of days left on a certificate to renew it.", + }, + // TODO(ldez): in v5, remove this flag, use this behavior as default. + &cli.BoolFlag{ + Name: flgRenewDynamic, + Value: false, + Usage: "Compute dynamically, based on the lifetime of the certificate(s), when to renew: use 1/3rd of the lifetime left, or 1/2 of the lifetime for short-lived certificates). This supersedes --days and will be the default behavior in Lego v5.", + }, + &cli.BoolFlag{ + Name: flgARIDisable, + Usage: "Do not use the renewalInfo endpoint (RFC9773) to check if a certificate should be renewed.", + }, + &cli.DurationFlag{ + Name: flgARIWaitToRenewDuration, + Usage: "The maximum duration you're willing to sleep for a renewal time returned by the renewalInfo endpoint.", + }, + &cli.BoolFlag{ + Name: flgReuseKey, + Usage: "Used to indicate you want to reuse your current private key for the new certificate.", + }, + &cli.BoolFlag{ + Name: flgNoRandomSleep, + Usage: "Do not add a random sleep before the renewal." + + " We do not recommend using this flag if you are doing your renewals in an automated way.", + }, + &cli.BoolFlag{ + Name: flgForceCertDomains, + Usage: "Check and ensure that the cert's domain list matches those passed in the domains argument.", + }, + ) + + return flags +} + func CreateDomainFlag() cli.Flag { return &cli.StringSliceFlag{ Name: flgDomains,