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

Method Run

command/kv_patch.go:146–280  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

144}
145
146func (c *KVPatchCommand) Run(args []string) int {
147 f := c.Flags()
148
149 if err := f.Parse(args); err != nil {
150 c.UI.Error(err.Error())
151 return 1
152 }
153
154 args = f.Args()
155 // Pull our fake stdin if needed
156 stdin := (io.Reader)(os.Stdin)
157 if c.testStdin != nil {
158 stdin = c.testStdin
159 }
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(c.flagRemoveData) == 0 && len(args) == 1:
166 c.UI.Error("Must supply data")
167 return 1
168 }
169
170 var err error
171
172 client, err := c.Client()
173 if err != nil {
174 c.UI.Error(err.Error())
175 return 2
176 }
177
178 newData, err := parseArgsData(stdin, args[1:])
179 if err != nil {
180 c.UI.Error(fmt.Sprintf("Failed to parse K=V data: %s", err))
181 return 1
182 }
183
184 // If true, we're working with "-mount=secret foo" syntax.
185 // If false, we're using "secret/foo" syntax.
186 mountFlagSyntax := c.flagMount != ""
187
188 var (
189 mountPath string
190 partialPath string
191 v2 bool
192 )
193
194 // Parse the paths and grab the KV version
195 if mountFlagSyntax {
196 // In this case, this arg is the secret path (e.g. "foo").
197 partialPath = sanitizePath(args[0])
198 mountPath, v2, err = isKVv2(sanitizePath(c.flagMount), client)
199 if err != nil {
200 c.UI.Error(err.Error())
201 return 2
202 }
203

Callers

nothing calls this directly

Calls 15

FlagsMethod · 0.95
readThenWriteMethod · 0.95
mergePatchMethod · 0.95
parseArgsDataFunction · 0.85
isKVv2Function · 0.85
addPrefixToKVPathFunction · 0.85
PrintRawFieldFunction · 0.85
OutputSecretFunction · 0.85
FormatFunction · 0.85
outputPathFunction · 0.85
getHeaderForMapFunction · 0.85
OutputDataFunction · 0.85

Tested by

no test coverage detected