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

Function handleWriteSecretOutput

command/write.go:154–192  ·  view source on GitHub ↗
(c *BaseCommand, path string, secret *api.Secret, err error)

Source from the content-addressed store, hash-verified

152}
153
154func handleWriteSecretOutput(c *BaseCommand, path string, secret *api.Secret, err error) int {
155 if err != nil {
156 c.UI.Error(fmt.Sprintf("Error writing data to %s: %s", path, err))
157 if secret != nil {
158 OutputSecret(c.UI, secret)
159 }
160 return 2
161 }
162 if secret == nil {
163 // Don't output anything unless using the "table" format
164 // and even then, don't output anything if a specific field was requested
165 if c.flagField == "" && Format(c.UI) == "table" {
166 c.UI.Info(fmt.Sprintf("Success! Data written to: %s", path))
167 }
168 return 0
169 }
170
171 // Currently, if there is only one MFA method configured, the login
172 // request is validated interactively
173 methodInfo := c.getInteractiveMFAMethodInfo(secret)
174 if methodInfo != nil {
175 secret, err = c.validateMFA(secret.Auth.MFARequirement.MFARequestID, *methodInfo)
176 if err != nil {
177 c.UI.Error(err.Error())
178 return 2
179 }
180 } else if c.getMFAValidationRequired(secret) {
181 c.UI.Warn(wrapAtLength("A login request was issued that is subject to "+
182 "MFA validation. Please make sure to validate the login by sending another "+
183 "request to sys/mfa/validate endpoint.") + "\n")
184 }
185
186 // Handle single field output
187 if c.flagField != "" {
188 return PrintRawField(c.UI, secret, c.flagField)
189 }
190
191 return OutputSecret(c.UI, secret)
192}

Callers 2

RunMethod · 0.85
RunMethod · 0.85

Calls 10

OutputSecretFunction · 0.85
FormatFunction · 0.85
wrapAtLengthFunction · 0.85
PrintRawFieldFunction · 0.85
validateMFAMethod · 0.80
ErrorMethod · 0.65
WarnMethod · 0.65
InfoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…