-
Notifications
You must be signed in to change notification settings - Fork 995
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
Move "Enter a password" cmd instructions to shared/cmd #5724
Changes from 2 commits
05dddc2
81d4fb4
3458b21
1743172
6bcecc0
25ed25f
c206139
91606f0
f1116cc
13826dc
30d1aee
d8685d7
331df8e
c4f140a
a64c600
12326f1
2356272
7eeb752
c38ea4d
d94ca0d
b501642
16920a7
1c703b4
605c37d
04bc4b5
24deb65
770cc41
e6c88c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"strings" | ||
|
||
"github.com/sirupsen/logrus" | ||
"golang.org/x/crypto/ssh/terminal" | ||
) | ||
|
||
var log = logrus.WithField("prefix", "node") | ||
|
@@ -42,3 +43,18 @@ func ConfirmAction(actionText string, deniedText string) (bool, error) { | |
|
||
return confirmed, nil | ||
} | ||
|
||
// EnterPassword queries the user for their password through the terminal, in order to make sure it is | ||
// not passed in a visible way to the terminal. | ||
func EnterPassword() (string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also is a good unit test candidate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 unit test would be good for this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Writing a test for |
||
var passphrase string | ||
log.Info("Enter a password:") | ||
bytePassword, err := terminal.ReadPassword(int(os.Stdin.Fd())) | ||
if err != nil { | ||
log.Fatalf("Could not read account password: %v", err) | ||
return passphrase, err | ||
} | ||
text := string(bytePassword) | ||
passphrase = strings.Replace(text, "\n", "", -1) | ||
return passphrase, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,10 @@ import ( | |
|
||
"github.com/pkg/errors" | ||
contract "github.com/prysmaticlabs/prysm/contracts/deposit-contract" | ||
"github.com/prysmaticlabs/prysm/shared/cmd" | ||
"github.com/prysmaticlabs/prysm/shared/keystore" | ||
"github.com/prysmaticlabs/prysm/shared/params" | ||
"github.com/sirupsen/logrus" | ||
"golang.org/x/crypto/ssh/terminal" | ||
) | ||
|
||
var log = logrus.WithField("prefix", "accounts") | ||
|
@@ -136,16 +136,13 @@ func Exists(keystorePath string) (bool, error) { | |
// CreateValidatorAccount creates a validator account from the given cli context. | ||
func CreateValidatorAccount(path string, passphrase string) (string, string, error) { | ||
if passphrase == "" { | ||
log.Info("Create a new validator account for eth2") | ||
log.Info("Enter a password:") | ||
bytePassword, err := terminal.ReadPassword(int(os.Stdin.Fd())) | ||
log.Info("Creating a new validator account for eth2") | ||
enteredPassphrase, err := cmd.EnterPassword() | ||
if err != nil { | ||
log.Fatalf("Could not read account password: %v", err) | ||
return path, passphrase, err | ||
log.Fatal(err) | ||
return path, enteredPassphrase, err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no point of returning the result here, when you have a fatal log above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this is duplicated several times in the validator client, was gonna make another PR making sure it's either handled or returned, never both. |
||
} | ||
text := string(bytePassword) | ||
passphrase = strings.Replace(text, "\n", "", -1) | ||
|
||
passphrase = enteredPassphrase | ||
} | ||
|
||
if path == "" { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functional comment