Merge pull request #700 from lino-network/KeyAddBug
Fix key add override bug
This commit is contained in:
commit
f2cf779117
|
@ -73,6 +73,28 @@ func GetCheckPassword(prompt, prompt2 string, buf *bufio.Reader) (string, error)
|
||||||
return pass, nil
|
return pass, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetConfirmation will request user give the confirmation from stdin.
|
||||||
|
// "y", "Y", "yes", "YES", and "Yes" all count as confirmations.
|
||||||
|
// If the input is not recognized, it will ask again.
|
||||||
|
func GetConfirmation(prompt string, buf *bufio.Reader) (bool, error) {
|
||||||
|
for {
|
||||||
|
if inputIsTty() {
|
||||||
|
fmt.Print(fmt.Sprintf("%s [y/n]:", prompt))
|
||||||
|
}
|
||||||
|
response, err := readLineFromBuf(buf)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
response = strings.ToLower(strings.TrimSpace(response))
|
||||||
|
if response == "y" || response == "yes" {
|
||||||
|
return true, nil
|
||||||
|
} else if response == "n" || response == "no" {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// inputIsTty returns true iff we have an interactive prompt,
|
// inputIsTty returns true iff we have an interactive prompt,
|
||||||
// where we can disable echo and request to repeat the password.
|
// where we can disable echo and request to repeat the password.
|
||||||
// If false, we can optimize for piped input from another command
|
// If false, we can optimize for piped input from another command
|
||||||
|
|
|
@ -60,6 +60,16 @@ func runAddCmd(cmd *cobra.Command, args []string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err := kb.Get(name)
|
||||||
|
if err == nil {
|
||||||
|
// account exists, ask for user confirmation
|
||||||
|
if response, err := client.GetConfirmation(
|
||||||
|
fmt.Sprintf("override the existing name %s", name), buf); err != nil || !response {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pass, err = client.GetCheckPassword(
|
pass, err = client.GetCheckPassword(
|
||||||
"Enter a passphrase for your key:",
|
"Enter a passphrase for your key:",
|
||||||
"Repeat the passphrase:", buf)
|
"Repeat the passphrase:", buf)
|
||||||
|
|
Loading…
Reference in New Issue