From 607d12174d9b0362d94cd2efb91ad4a0266340c9 Mon Sep 17 00:00:00 2001 From: Mathias Lafeldt Date: Thu, 10 Dec 2015 10:01:22 +0100 Subject: [PATCH] Output secrets sorted by key Instead of printing them in random order each time `vault read` is invoked. --- command/format.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/command/format.go b/command/format.go index 4edb44091..b53e1c857 100644 --- a/command/format.go +++ b/command/format.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "sort" "strconv" "github.com/hashicorp/vault/api" @@ -68,8 +69,14 @@ func outputFormatTable(ui cli.Ui, s *api.Secret, whitespace bool) int { } } - for k, v := range s.Data { - input = append(input, fmt.Sprintf("%s %s %v", k, config.Delim, v)) + keys := make([]string, 0, len(s.Data)) + for k := range s.Data { + keys = append(keys, k) + } + sort.Strings(keys) + + for _, k := range keys { + input = append(input, fmt.Sprintf("%s %s %v", k, config.Delim, s.Data[k])) } if len(s.Warnings) != 0 {