MCPcopy Create free account
hub / github.com/hashicorp/vault / Run

Method Run

command/namespace_create.go:73–115  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

71}
72
73func (c *NamespaceCreateCommand) Run(args []string) int {
74 f := c.Flags()
75
76 if err := f.Parse(args); err != nil {
77 c.UI.Error(err.Error())
78 return 1
79 }
80
81 args = f.Args()
82 switch {
83 case len(args) < 1:
84 c.UI.Error(fmt.Sprintf("Not enough arguments (expected 1, got %d)", len(args)))
85 return 1
86 case len(args) > 1:
87 c.UI.Error(fmt.Sprintf("Too many arguments (expected 1, got %d)", len(args)))
88 return 1
89 }
90
91 namespacePath := strings.TrimSpace(args[0])
92
93 client, err := c.Client()
94 if err != nil {
95 c.UI.Error(err.Error())
96 return 2
97 }
98
99 data := map[string]interface{}{
100 "custom_metadata": c.flagCustomMetadata,
101 }
102
103 secret, err := client.Logical().Write("sys/namespaces/"+namespacePath, data)
104 if err != nil {
105 c.UI.Error(fmt.Sprintf("Error creating namespace: %s", err))
106 return 2
107 }
108
109 // Handle single field output
110 if c.flagField != "" {
111 return PrintRawField(c.UI, secret, c.flagField)
112 }
113
114 return OutputSecret(c.UI, secret)
115}

Callers

nothing calls this directly

Calls 9

FlagsMethod · 0.95
PrintRawFieldFunction · 0.85
OutputSecretFunction · 0.85
ArgsMethod · 0.80
LogicalMethod · 0.80
ParseMethod · 0.65
ErrorMethod · 0.65
ClientMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected