2018-02-22 07:17:19 -08:00
|
|
|
package keys
|
|
|
|
|
|
|
|
import (
|
2018-11-29 12:55:23 -08:00
|
|
|
"bufio"
|
|
|
|
|
2020-10-08 10:41:35 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2019-05-28 01:44:04 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/input"
|
2020-03-25 08:20:36 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
2018-02-22 07:17:19 -08:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2018-11-29 12:55:23 -08:00
|
|
|
const (
|
2018-11-30 12:36:55 -08:00
|
|
|
flagYes = "yes"
|
|
|
|
flagForce = "force"
|
2018-11-29 12:55:23 -08:00
|
|
|
)
|
|
|
|
|
2019-12-12 13:52:24 -08:00
|
|
|
// DeleteKeyCommand deletes a key from the key store.
|
|
|
|
func DeleteKeyCommand() *cobra.Command {
|
2018-02-22 08:20:25 -08:00
|
|
|
cmd := &cobra.Command{
|
2019-12-05 07:07:29 -08:00
|
|
|
Use: "delete <name>...",
|
|
|
|
Short: "Delete the given keys",
|
|
|
|
Long: `Delete keys from the Keybase backend.
|
2018-11-29 12:55:23 -08:00
|
|
|
|
|
|
|
Note that removing offline or ledger keys will remove
|
|
|
|
only the public key references stored locally, i.e.
|
2019-05-18 01:42:24 -07:00
|
|
|
private keys stored in a ledger device cannot be deleted with the CLI.
|
2018-11-29 12:55:23 -08:00
|
|
|
`,
|
2019-12-05 07:07:29 -08:00
|
|
|
Args: cobra.MinimumNArgs(1),
|
2020-07-06 12:50:09 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
buf := bufio.NewReader(cmd.InOrStdin())
|
2020-12-14 14:09:51 -08:00
|
|
|
clientCtx, err := client.GetClientQueryContext(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-02-22 07:17:19 -08:00
|
|
|
|
2020-07-06 12:50:09 -07:00
|
|
|
for _, name := range args {
|
2021-09-20 05:02:15 -07:00
|
|
|
k, err := clientCtx.Keyring.Key(name)
|
2020-07-06 12:50:09 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-02-22 07:17:19 -08:00
|
|
|
|
2020-07-06 12:50:09 -07:00
|
|
|
// confirm deletion, unless -y is passed
|
|
|
|
if skip, _ := cmd.Flags().GetBool(flagYes); !skip {
|
|
|
|
if yes, err := input.GetConfirmation("Key reference will be deleted. Continue?", buf, cmd.ErrOrStderr()); err != nil {
|
|
|
|
return err
|
|
|
|
} else if !yes {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
2018-02-22 07:17:19 -08:00
|
|
|
|
2020-10-08 10:41:35 -07:00
|
|
|
if err := clientCtx.Keyring.Delete(name); err != nil {
|
2020-07-06 12:50:09 -07:00
|
|
|
return err
|
|
|
|
}
|
2018-07-05 18:03:41 -07:00
|
|
|
|
2021-09-20 05:02:15 -07:00
|
|
|
if k.GetType() == keyring.TypeLedger || k.GetType() == keyring.TypeOffline {
|
2020-07-06 12:50:09 -07:00
|
|
|
cmd.PrintErrln("Public key reference deleted")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
cmd.PrintErrln("Key deleted forever (uh oh!)")
|
2018-11-29 12:55:23 -08:00
|
|
|
}
|
2020-04-08 02:38:28 -07:00
|
|
|
|
2020-07-06 12:50:09 -07:00
|
|
|
return nil
|
|
|
|
},
|
2018-11-29 12:55:23 -08:00
|
|
|
}
|
|
|
|
|
2020-07-06 12:50:09 -07:00
|
|
|
cmd.Flags().BoolP(flagYes, "y", false, "Skip confirmation prompt when deleting offline or ledger key references")
|
|
|
|
cmd.Flags().BoolP(flagForce, "f", false, "Remove the key unconditionally without asking for the passphrase. Deprecated.")
|
|
|
|
|
|
|
|
return cmd
|
2018-02-22 07:17:19 -08:00
|
|
|
}
|