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

cli: Allow to create account without email #1378

Open
wants to merge 1 commit 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
7 changes: 3 additions & 4 deletions cmd/accounts_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions cmd/cmd_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
16 changes: 10 additions & 6 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down