diff --git a/cmd/accounts_storage.go b/cmd/accounts_storage.go index df398f36e3..4d249b2d77 100644 --- a/cmd/accounts_storage.go +++ b/cmd/accounts_storage.go @@ -71,8 +71,7 @@ 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) + userID := getUserID(ctx) serverURL, err := url.Parse(ctx.GlobalString("server")) if err != nil { @@ -82,10 +81,10 @@ func NewAccountsStorage(ctx *cli.Context) *AccountsStorage { rootPath := filepath.Join(ctx.GlobalString("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, + userID: userID, rootPath: rootPath, rootUserPath: rootUserPath, keysPath: filepath.Join(rootUserPath, baseKeysFolderName), diff --git a/cmd/cmd_list.go b/cmd/cmd_list.go index 68fd0c7079..01f642fdfd 100644 --- a/cmd/cmd_list.go +++ b/cmd/cmd_list.go @@ -91,8 +91,8 @@ func listCertificates(ctx *cli.Context) error { } func listAccount(ctx *cli.Context) error { - // fake email, needed by NewAccountsStorage - if err := ctx.GlobalSet("email", "unknown"); err != nil { + // fake userID, needed by NewAccountsStorage + if err := ctx.GlobalSet("user-id", "unknown"); err != nil { return err } diff --git a/cmd/flags.go b/cmd/flags.go index 8307b2c9f3..a73424d4d6 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -24,6 +24,10 @@ func CreateFlags(defaultPath string) []cli.Flag { Name: "email, m", Usage: "Email used for registration and recovery contact.", }, + cli.StringFlag{ + Name: "user-id", + Usage: "Local userID. The default is to use the given email.", + }, cli.StringFlag{ Name: "csr, c", Usage: "Certificate signing request filename, if an external CSR is to be used.", diff --git a/cmd/setup.go b/cmd/setup.go index e2a41a57e4..4ad2762a00 100644 --- a/cmd/setup.go +++ b/cmd/setup.go @@ -26,7 +26,8 @@ func setup(ctx *cli.Context, accountsStorage *AccountsStorage) (*Account, *lego. if accountsStorage.ExistsAccountFilePath() { account = accountsStorage.LoadAccount(privateKey) } else { - account = &Account{Email: accountsStorage.GetUserID(), key: privateKey} + email := ctx.GlobalString("email") + account = &Account{Email: email, key: privateKey} } client := newClient(ctx, account, keyType) @@ -80,12 +81,15 @@ func getKeyType(ctx *cli.Context) certcrypto.KeyType { return "" } -func getEmail(ctx *cli.Context) string { - email := ctx.GlobalString("email") - if email == "" { - log.Fatal("You have to pass an account (email address) to the program using --email or -m") +func getUserID(ctx *cli.Context) string { + userID := ctx.GlobalString("user-id") + if userID == "" { + userID = ctx.GlobalString("email") } - return email + if userID == "" { + log.Fatal("You have to pass an account to the program using --email or -m (email address) or --user-id") + } + return userID } func createNonExistingFolder(path string) error {