Adds -base64 support to kv get command.

Fixes #3736
This commit is contained in:
James Phillips 2017-12-14 17:27:45 -08:00
parent 25f7234cc4
commit c676e6b8c8
No known key found for this signature in database
GPG Key ID: 77183E682AC5FC11
2 changed files with 40 additions and 1 deletions

View File

@ -169,7 +169,11 @@ func (c *cmd) Run(args []string) int {
return 0
}
if c.base64encode {
c.UI.Info(base64.StdEncoding.EncodeToString(pair.Value))
} else {
c.UI.Info(string(pair.Value))
}
return 0
}
}

View File

@ -91,6 +91,41 @@ func TestKVGetCommand(t *testing.T) {
}
}
func TestKVGetCommand_Base64(t *testing.T) {
t.Parallel()
a := agent.NewTestAgent(t.Name(), ``)
defer a.Shutdown()
client := a.Client()
ui := cli.NewMockUi()
c := New(ui)
pair := &api.KVPair{
Key: "foo",
Value: []byte("bar"),
}
_, err := client.KV().Put(pair, nil)
if err != nil {
t.Fatalf("err: %#v", err)
}
args := []string{
"-http-addr=" + a.HTTPAddr(),
"-base64",
"foo",
}
code := c.Run(args)
if code != 0 {
t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String())
}
output := ui.OutputWriter.String()
if !strings.Contains(output, base64.StdEncoding.EncodeToString(pair.Value)) {
t.Errorf("bad: %#v", output)
}
}
func TestKVGetCommand_Missing(t *testing.T) {
t.Parallel()
a := agent.NewTestAgent(t.Name(), ``)