From 758cf7531dd71dca9d48e1aa63ca1cddf464ad85 Mon Sep 17 00:00:00 2001 From: hc-github-team-secure-vault-core <82990506+hc-github-team-secure-vault-core@users.noreply.github.com> Date: Wed, 19 Apr 2023 09:59:40 -0400 Subject: [PATCH] backport of commit 98786d96c7b246e8ed303ae769b0ac399e1d185d (#20250) Co-authored-by: Jason O'Donnell <2160810+jasonodonnell@users.noreply.github.com> --- changelog/20243.txt | 4 ++++ command/namespace_list.go | 17 ++++++++++++++++- website/content/docs/commands/namespace.mdx | 6 ++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 changelog/20243.txt diff --git a/changelog/20243.txt b/changelog/20243.txt new file mode 100644 index 000000000000..8d5b04420b97 --- /dev/null +++ b/changelog/20243.txt @@ -0,0 +1,4 @@ +```release-note:improvement +cli/namespace: Add detailed flag to output additional namespace information +such as namespace IDs and custom metadata. +``` diff --git a/command/namespace_list.go b/command/namespace_list.go index 605c4e32e28f..2be2a3874df5 100644 --- a/command/namespace_list.go +++ b/command/namespace_list.go @@ -37,7 +37,18 @@ Usage: vault namespace list [options] } func (c *NamespaceListCommand) Flags() *FlagSets { - return c.flagSet(FlagSetHTTP | FlagSetOutputFormat) + set := c.flagSet(FlagSetHTTP | FlagSetOutputFormat) + + f := set.NewFlagSet("Command Options") + + f.BoolVar(&BoolVar{ + Name: "detailed", + Target: &c.flagDetailed, + Default: false, + Usage: "Print detailed information such as namespace ID.", + }) + + return set } func (c *NamespaceListCommand) AutocompleteArgs() complete.Predictor { @@ -101,5 +112,9 @@ func (c *NamespaceListCommand) Run(args []string) int { return 2 } + if c.flagDetailed && Format(c.UI) != "table" { + return OutputData(c.UI, secret.Data["key_info"]) + } + return OutputList(c.UI, secret) } diff --git a/website/content/docs/commands/namespace.mdx b/website/content/docs/commands/namespace.mdx index 5913386a9eea..d52a3fa88af1 100644 --- a/website/content/docs/commands/namespace.mdx +++ b/website/content/docs/commands/namespace.mdx @@ -16,6 +16,12 @@ List all namespaces: $ vault namespace list ``` +List all namespaces with additional details such as namespace ID and custom metadata: + +```shell-session +$ vault namespace list -detailed +``` + Create a namespace at the path `ns1/` with no custom metadata: ```shell-session