mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-28 20:21:47 +00:00
Add update cli command, cleanup
This commit is contained in:
14
cmd/new.go
14
cmd/new.go
@ -36,26 +36,16 @@ func init() {
|
|||||||
|
|
||||||
func newPassword(cmd *cobra.Command, args []string) {
|
func newPassword(cmd *cobra.Command, args []string) {
|
||||||
if len(args) != 1 || len(args[0]) == 0 {
|
if len(args) != 1 || len(args[0]) == 0 {
|
||||||
fmt.Print("You must provide a name for the key")
|
fmt.Println("You must provide a name for the key")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
name := args[0]
|
name := args[0]
|
||||||
|
|
||||||
// TODO: own function???
|
pass, err := getCheckPassword("Enter a passphrase:", "Repeat the passphrase:")
|
||||||
pass, err := getPassword("Enter a passphrase:")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pass2, err := getPassword("Repeat the passphrase:")
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if pass != pass2 {
|
|
||||||
fmt.Println("Passphrases don't match")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
info, err := manager.Create(name, pass)
|
info, err := manager.Create(name, pass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -18,7 +18,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// updateCmd represents the update command
|
// updateCmd represents the update command
|
||||||
@ -26,14 +25,35 @@ var updateCmd = &cobra.Command{
|
|||||||
Use: "update",
|
Use: "update",
|
||||||
Short: "Change the password for a private key",
|
Short: "Change the password for a private key",
|
||||||
Long: `Change the password for a private key.`,
|
Long: `Change the password for a private key.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: updatePassword,
|
||||||
// TODO: Work your own magic here
|
|
||||||
fmt.Println(viper.Get("name"))
|
|
||||||
fmt.Println("update called")
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RootCmd.AddCommand(updateCmd)
|
RootCmd.AddCommand(updateCmd)
|
||||||
updateCmd.Flags().StringP("name", "n", "", "Name of key to update")
|
}
|
||||||
|
|
||||||
|
func updatePassword(cmd *cobra.Command, args []string) {
|
||||||
|
if len(args) != 1 || len(args[0]) == 0 {
|
||||||
|
fmt.Println("You must provide a name for the key")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
name := args[0]
|
||||||
|
|
||||||
|
oldpass, err := getPassword("Enter the current passphrase:")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
newpass, err := getCheckPassword("Enter the new passphrase:", "Repeat the new passphrase:")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = manager.Update(name, oldpass, newpass)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
} else {
|
||||||
|
fmt.Println("Password successfully updated!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
16
cmd/utils.go
16
cmd/utils.go
@ -22,6 +22,22 @@ func getPassword(prompt string) (string, error) {
|
|||||||
return pass, nil
|
return pass, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getCheckPassword(prompt, prompt2 string) (string, error) {
|
||||||
|
// TODO: own function???
|
||||||
|
pass, err := getPassword(prompt)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
pass2, err := getPassword(prompt2)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if pass != pass2 {
|
||||||
|
return "", errors.New("Passphrases don't match")
|
||||||
|
}
|
||||||
|
return pass, nil
|
||||||
|
}
|
||||||
|
|
||||||
func printInfo(info keys.Info) {
|
func printInfo(info keys.Info) {
|
||||||
switch output {
|
switch output {
|
||||||
case "text":
|
case "text":
|
||||||
|
Reference in New Issue
Block a user