Skip to content

Commit

Permalink
cli: debug decode-key to support base64
Browse files Browse the repository at this point in the history
Previously decode-key supported hex encoded keys. When using
json serialization of descriptors and recovery plans you need
to decode keys that are base64 encoded and may be non mvcc.
This patch adds flags to select formats and keys types to the
decoded.
The default mode stays the same so any existing tooling will
work as expected.

Release note: None
  • Loading branch information
aliher1911 committed Mar 21, 2022
1 parent b3525c9 commit 7e85fbc
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pkg/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,19 +528,29 @@ func runDebugRangeDescriptors(cmd *cobra.Command, args []string) error {
})
}

var decodeKeyOptions struct {
useBase64 bool
}

var debugDecodeKeyCmd = &cobra.Command{
Use: "decode-key",
Short: "decode <key>",
Long: `
Decode a hexadecimal-encoded key and pretty-print it. For example:
Decode a hexadecimal or base64 encoded key and pretty-print it. For example:
$ decode-key BB89F902ADB43000151C2D1ED07DE6C009
/Table/51/1/44938288/1521140384.514565824,0
`,
Args: cobra.ArbitraryArgs,
RunE: func(cmd *cobra.Command, args []string) error {
for _, arg := range args {
b, err := gohex.DecodeString(arg)
var b []byte
var err error
if decodeKeyOptions.useBase64 {
b, err = base64.StdEncoding.DecodeString(arg)
} else {
b, err = gohex.DecodeString(arg)
}
if err != nil {
return err
}
Expand Down Expand Up @@ -1697,6 +1707,9 @@ func init() {
f.Var(&debugMergeLogsOpts.useColor, "color",
"force use of TTY escape codes to colorize the output")

f = debugDecodeKeyCmd.Flags()
f.BoolVar(&decodeKeyOptions.useBase64, "base64", false, "use base64 encoding for keys")

f = debugDecodeProtoCmd.Flags()
f.StringVar(&debugDecodeProtoName, "schema", "cockroach.sql.sqlbase.Descriptor",
"fully qualified name of the proto to decode")
Expand Down

0 comments on commit 7e85fbc

Please sign in to comment.