(c *BaseCommand, path string, secret *api.Secret, err error)
| 152 | } |
| 153 | |
| 154 | func 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 | } |
no test coverage detected
searching dependent graphs…