in app.go [215:251]
func (app *App) mfaDevice() (string, error) {
devices, err := app.aws.MFADevices()
if err != nil {
return "", err
}
if len(devices) < 1 {
return "", errors.New("no MFA devices found")
}
if len(devices) == 1 {
return devices[0], nil
}
Prompt:
for i, device := range devices {
fmt.Fprintf(app.stderr, "[%d]: %s\n", i+1, device)
}
app.stderr.Write([]byte("Select MFA device: "))
userInput, err := readInput(app.stdinReader)
if err != nil {
return "", fmt.Errorf("unable to read MFA device option from stdin: %v", err)
}
userInputInt, err := strconv.Atoi(userInput)
if err != nil {
app.stderr.Write([]byte("Invalid input (not a number)\n"))
goto Prompt
}
if userInputInt < 1 || userInputInt > len(devices) {
app.stderr.Write([]byte("Invalid input (not in range)\n"))
goto Prompt
}
return devices[userInputInt-1], nil
}