diff --git a/command/format.go b/command/format.go index 26683c446..42da6a4af 100644 --- a/command/format.go +++ b/command/format.go @@ -35,9 +35,7 @@ func OutputList(ui cli.Ui, format string, secret *api.Secret) int { case "yaml": return outputFormatYAMLList(ui, secret) case "table": - return outputFormatTableList(ui, secret, false) - case "bare": - return outputFormatTableList(ui, secret, true) + return outputFormatTableList(ui, secret) default: ui.Error(fmt.Sprintf("Invalid output format: %s", format)) return 1 @@ -150,7 +148,7 @@ func outputFormatTable(ui cli.Ui, s *api.Secret, whitespace bool) int { return 0 } -func outputFormatTableList(ui cli.Ui, s *api.Secret, bare bool) int { +func outputFormatTableList(ui cli.Ui, s *api.Secret) int { config := columnize.DefaultConfig() config.Delim = "♨" config.Glue = "\t" @@ -158,13 +156,11 @@ func outputFormatTableList(ui cli.Ui, s *api.Secret, bare bool) int { input := make([]string, 0, 5) - if !bare { - input = append(input, "Keys") - } + input = append(input, "Keys") - keys := make([]string, 0, len(s.Data["keys"].([]string))) - for _, k := range s.Data["keys"].([]string) { - keys = append(keys, k) + keys := make([]string, 0, len(s.Data["keys"].([]interface{}))) + for _, k := range s.Data["keys"].([]interface{}) { + keys = append(keys, k.(string)) } sort.Strings(keys) @@ -172,19 +168,13 @@ func outputFormatTableList(ui cli.Ui, s *api.Secret, bare bool) int { input = append(input, fmt.Sprintf("%s", k)) } - if !bare && len(s.Warnings) != 0 { + if len(s.Warnings) != 0 { input = append(input, "") for _, warning := range s.Warnings { input = append(input, fmt.Sprintf("* %s", warning)) } } - if bare { - for _, line := range input { - ui.Output(line) - } - } else { - ui.Output(columnize.Format(input, config)) - } + ui.Output(columnize.Format(input, config)) return 0 } diff --git a/command/list.go b/command/list.go index 56153095b..61f9f245c 100644 --- a/command/list.go +++ b/command/list.go @@ -15,13 +15,11 @@ type ListCommand struct { func (c *ListCommand) Run(args []string) int { var format string - var bare bool var err error var secret *api.Secret var flags *flag.FlagSet flags = c.Meta.FlagSet("list", FlagSetDefault) flags.StringVar(&format, "format", "table", "") - flags.BoolVar(&bare, "bare", false, "") flags.Usage = func() { c.Ui.Error(c.Help()) } if err := flags.Parse(args); err != nil { return 1 @@ -58,16 +56,10 @@ func (c *ListCommand) Run(args []string) int { return 1 } if secret.Data["keys"] == nil { - if !bare { - c.Ui.Error("No entries found") - } + c.Ui.Error("No entries found") return 0 } - if bare { - return OutputList(c.Ui, "bare", secret) - } - return OutputList(c.Ui, format, secret) } @@ -93,9 +85,6 @@ Read Options: -format=table The format for output. By default it is a whitespace- delimited table. This can also be json or yaml. - - -bare Causes the key values to be output raw to stdout, - without formatting (except for newlines). ` return strings.TrimSpace(helpText) } diff --git a/vault/logical_cubbyhole.go b/vault/logical_cubbyhole.go index ccec06744..7da0ef7fd 100644 --- a/vault/logical_cubbyhole.go +++ b/vault/logical_cubbyhole.go @@ -117,6 +117,11 @@ func (b *CubbyholeBackend) handleWrite( return nil, fmt.Errorf("missing data fields") } + path := req.Path + if strings.HasSuffix(path, "/") { + path = path[:len(path)-1] + } + // JSON encode the data buf, err := json.Marshal(req.Data) if err != nil { @@ -125,7 +130,7 @@ func (b *CubbyholeBackend) handleWrite( // Write out a new key entry := &logical.StorageEntry{ - Key: req.ClientToken + "/" + req.Path, + Key: req.ClientToken + "/" + path, Value: buf, } if err := req.Storage.Put(entry); err != nil { @@ -164,7 +169,12 @@ func (b *CubbyholeBackend) handleList( // passthrough strippedKeys := make([]string, len(keys)) for i, key := range keys { - strippedKeys[i] = req.MountPoint + req.Path + strings.TrimPrefix(key, req.ClientToken+"/") + ret := strings.TrimPrefix(key, req.ClientToken+"/") + if ret == "" { + strippedKeys[i] = "." + } else { + strippedKeys[i] = ret + } } // Generate the response diff --git a/vault/logical_passthrough.go b/vault/logical_passthrough.go index 90d4c7046..779f7ca18 100644 --- a/vault/logical_passthrough.go +++ b/vault/logical_passthrough.go @@ -165,6 +165,11 @@ func (b *PassthroughBackend) handleWrite( return logical.ErrorResponse("missing data fields"), nil } + path := req.Path + if strings.HasSuffix(path, "/") { + path = path[:len(path)-1] + } + // Check if there is a ttl key; verify parseability if so var ttl string ttl = data.Get("ttl").(string) @@ -190,7 +195,7 @@ func (b *PassthroughBackend) handleWrite( // Write out a new key entry := &logical.StorageEntry{ - Key: req.Path, + Key: path, Value: buf, } if err := req.Storage.Put(entry); err != nil { @@ -223,7 +228,11 @@ func (b *PassthroughBackend) handleList( // path and let users do what they wish. retKeys := make([]string, len(keys)) for i, k := range keys { - retKeys[i] = req.MountPoint + req.Path + k + if k == "" { + retKeys[i] = "." + } else { + retKeys[i] = k + } } // Generate the response