-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
client/keys: print out pubkeys in JSON format #808
Changes from all commits
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 | ||
---|---|---|---|---|
|
@@ -2,20 +2,29 @@ package keys | |||
|
||||
import ( | ||||
"encoding/json" | ||||
"fmt" | ||||
"net/http" | ||||
|
||||
"github.com/gorilla/mux" | ||||
"github.com/pkg/errors" | ||||
"github.com/spf13/cobra" | ||||
"github.com/spf13/viper" | ||||
keys "github.com/tendermint/go-crypto/keys" | ||||
) | ||||
|
||||
"github.com/spf13/cobra" | ||||
const ( | ||||
flagExportPubKey = "export-pubkey" | ||||
) | ||||
|
||||
var showKeysCmd = &cobra.Command{ | ||||
Use: "show <name>", | ||||
Short: "Show key info for the given name", | ||||
Long: `Return public details of one local key.`, | ||||
RunE: runShowCmd, | ||||
Args: cobra.ExactArgs(1), | ||||
} | ||||
|
||||
func init() { | ||||
showKeysCmd.Flags().Bool(flagExportPubKey, false, "Export public key.") | ||||
} | ||||
|
||||
func getKey(name string) (keys.Info, error) { | ||||
|
@@ -30,16 +39,20 @@ func getKey(name string) (keys.Info, error) { | |||
// CMD | ||||
|
||||
func runShowCmd(cmd *cobra.Command, args []string) error { | ||||
if len(args) != 1 || len(args[0]) == 0 { | ||||
return errors.New("You must provide a name for the key") | ||||
info, err := getKey(args[0]) | ||||
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. We should still check the length of 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. See github.com/spf13/cobra.ExactArgs() |
||||
if err != nil { | ||||
return err | ||||
} | ||||
name := args[0] | ||||
|
||||
info, err := getKey(name) | ||||
if err == nil { | ||||
printInfo(info) | ||||
if viper.GetBool(flagExportPubKey) { | ||||
out, err := info.PubKey.MarshalJSON() | ||||
if err != nil { | ||||
return err | ||||
} | ||||
fmt.Println(string(out)) | ||||
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. I don't like the idea of moving out of the current process train of printing everything through the cosmos-sdk/client/keys/utils.go Line 58 in 18ac0f9
maybe with a table header so it would look like:
just need to make sure we'd get it right for 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. Hi! Apologies for the late reply.
True, but the following prints the private key out too:
Furthermore, the public key JSON format seems a bit fuzzy:
That's fair, I'd be happy with that too! I just need to allow users to exchange public keys in a portable format, be it a string or a JSON thing. 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. So it sounds like we just want to improve the JSON output format, which I could totally get behind - maybe don't print the private key by default too 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. Okay yeah the validator json key is not a HEX string which stinks |
||||
return nil | ||||
} | ||||
return err | ||||
printInfo(info) | ||||
return nil | ||||
} | ||||
|
||||
// REST | ||||
|
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.
@cwgoes nope, this just does it
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.
Ah, got it.