mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-03 03:58:01 +00:00
VAULT-7256: Add custom_metadata to namespaces (#16640)
* add mapstructure tags to Namespace struct * add custom metadata Parse helper * add ns custom metadata and patch
This commit is contained in:
@@ -15,6 +15,8 @@ var (
|
||||
|
||||
type NamespaceCreateCommand struct {
|
||||
*BaseCommand
|
||||
|
||||
flagCustomMetadata map[string]string
|
||||
}
|
||||
|
||||
func (c *NamespaceCreateCommand) Synopsis() string {
|
||||
@@ -43,7 +45,18 @@ Usage: vault namespace create [options] PATH
|
||||
}
|
||||
|
||||
func (c *NamespaceCreateCommand) Flags() *FlagSets {
|
||||
return c.flagSet(FlagSetHTTP | FlagSetOutputField | FlagSetOutputFormat)
|
||||
set := c.flagSet(FlagSetHTTP | FlagSetOutputField | FlagSetOutputFormat)
|
||||
|
||||
f := set.NewFlagSet("Command Options")
|
||||
f.StringMapVar(&StringMapVar{
|
||||
Name: "custom-metadata",
|
||||
Target: &c.flagCustomMetadata,
|
||||
Default: map[string]string{},
|
||||
Usage: "Specifies arbitrary key=value metadata meant to describe a namespace." +
|
||||
"This can be specified multiple times to add multiple pieces of metadata.",
|
||||
})
|
||||
|
||||
return set
|
||||
}
|
||||
|
||||
func (c *NamespaceCreateCommand) AutocompleteArgs() complete.Predictor {
|
||||
@@ -80,7 +93,11 @@ func (c *NamespaceCreateCommand) Run(args []string) int {
|
||||
return 2
|
||||
}
|
||||
|
||||
secret, err := client.Logical().Write("sys/namespaces/"+namespacePath, nil)
|
||||
data := map[string]interface{}{
|
||||
"custom_metadata": c.flagCustomMetadata,
|
||||
}
|
||||
|
||||
secret, err := client.Logical().Write("sys/namespaces/"+namespacePath, data)
|
||||
if err != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error creating namespace: %s", err))
|
||||
return 2
|
||||
|
||||
Reference in New Issue
Block a user