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

Method Run

command/kv_metadata_patch.go:151–262  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

149}
150
151func (c *KVMetadataPatchCommand) Run(args []string) int {
152 f := c.Flags()
153
154 if err := f.Parse(args); err != nil {
155 c.UI.Error(err.Error())
156 return 1
157 }
158
159 args = f.Args()
160
161 switch {
162 case len(args) < 1:
163 c.UI.Error(fmt.Sprintf("Not enough arguments (expected 1, got %d)", len(args)))
164 return 1
165 case len(args) > 1:
166 c.UI.Error(fmt.Sprintf("Too many arguments (expected 1, got %d)", len(args)))
167 return 1
168 }
169
170 client, err := c.Client()
171 if err != nil {
172 c.UI.Error(err.Error())
173 return 2
174 }
175
176 // If true, we're working with "-mount=secret foo" syntax.
177 // If false, we're using "secret/foo" syntax.
178 mountFlagSyntax := c.flagMount != ""
179
180 var (
181 mountPath string
182 partialPath string
183 v2 bool
184 )
185
186 // Parse the paths and grab the KV version
187 if mountFlagSyntax {
188 // In this case, this arg is the secret path (e.g. "foo").
189 partialPath = sanitizePath(args[0])
190 mountPath, v2, err = isKVv2(sanitizePath(c.flagMount), client)
191 if err != nil {
192 c.UI.Error(err.Error())
193 return 2
194 }
195
196 if v2 {
197 partialPath = path.Join(mountPath, partialPath)
198 }
199 } else {
200 // In this case, this arg is a path-like combination of mountPath/secretPath.
201 // (e.g. "secret/foo")
202 partialPath = sanitizePath(args[0])
203 mountPath, v2, err = isKVv2(partialPath, client)
204 if err != nil {
205 c.UI.Error(err.Error())
206 return 2
207 }
208 }

Callers

nothing calls this directly

Calls 15

FlagsMethod · 0.95
isKVv2Function · 0.85
addPrefixToKVPathFunction · 0.85
OutputSecretFunction · 0.85
FormatFunction · 0.85
ArgsMethod · 0.80
IsSetMethod · 0.80
JSONMergePatchMethod · 0.80
LogicalMethod · 0.80
sanitizePathFunction · 0.70
ParseMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected