Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --no-email for disabling email in ACME query #2060

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions cmd/accounts_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const (
// │ └── root accounts directory
// └── "path" option
type AccountsStorage struct {
noEmail bool
userID string
rootPath string
rootUserPath string
Expand All @@ -68,8 +69,14 @@ type AccountsStorage struct {

// NewAccountsStorage Creates a new AccountsStorage.
func NewAccountsStorage(ctx *cli.Context) *AccountsStorage {
// TODO: move to account struct? Currently MUST pass email.
email := getEmail(ctx)
var userID string
noEmail := ctx.IsSet("no-email")
if noEmail {
userID = "default"
} else {
// TODO: move to account struct?
userID = getEmail(ctx)
}

serverURL, err := url.Parse(ctx.String("server"))
if err != nil {
Expand All @@ -79,10 +86,11 @@ func NewAccountsStorage(ctx *cli.Context) *AccountsStorage {
rootPath := filepath.Join(ctx.String("path"), baseAccountsRootFolderName)
serverPath := strings.NewReplacer(":", "_", "/", string(os.PathSeparator)).Replace(serverURL.Host)
accountsPath := filepath.Join(rootPath, serverPath)
rootUserPath := filepath.Join(accountsPath, email)
rootUserPath := filepath.Join(accountsPath, userID)

return &AccountsStorage{
userID: email,
noEmail: noEmail,
userID: userID,
rootPath: rootPath,
rootUserPath: rootUserPath,
keysPath: filepath.Join(rootUserPath, baseKeysFolderName),
Expand Down Expand Up @@ -110,6 +118,9 @@ func (s *AccountsStorage) GetRootUserPath() string {
}

func (s *AccountsStorage) GetUserID() string {
if s.noEmail {
return ""
}
return s.userID
}

Expand Down
6 changes: 6 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func CreateFlags(defaultPath string) []cli.Flag {
Aliases: []string{"m"},
Usage: "Email used for registration and recovery contact.",
},
&cli.BoolFlag{
Name: "no-email",
Aliases: []string{"M"},
EnvVars: []string{"LEGO_NO_EMAIL"},
Usage: "Create an ACME request without including an email address.",
},
&cli.StringFlag{
Name: "csr",
Aliases: []string{"c"},
Expand Down
2 changes: 1 addition & 1 deletion cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func getKeyType(ctx *cli.Context) certcrypto.KeyType {
func getEmail(ctx *cli.Context) string {
email := ctx.String("email")
if email == "" {
log.Fatal("You have to pass an account (email address) to the program using --email or -m")
log.Fatal("You have to pass an account (email address) to the program using --email or -m, or use --no-email or -M to disable including an email in the ACME request.")
}
return email
}
Expand Down
1 change: 1 addition & 0 deletions docs/data/zz_cli_help.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ GLOBAL OPTIONS:
--server value, -s value CA hostname (and optionally :port). The server certificate must be trusted in order to avoid further modifications to the client. (default: "https://acme-v02.api.letsencrypt.org/directory")
--accept-tos, -a By setting this flag to true you indicate that you accept the current Let's Encrypt terms of service. (default: false)
--email value, -m value Email used for registration and recovery contact.
--no-email, -M Create an ACME request without including an email address. (default: false) [$LEGO_NO_EMAIL]
--csr value, -c value Certificate signing request filename, if an external CSR is to be used.
--eab Use External Account Binding for account registration. Requires --kid and --hmac. (default: false) [$LEGO_EAB]
--kid value Key identifier from External CA. Used for External Account Binding. [$LEGO_EAB_KID]
Expand Down
Loading