(ctx context.Context, remainingRetries int)
| 49 | } |
| 50 | |
| 51 | func askForPasswordWithRetry(ctx context.Context, remainingRetries int) (string, string, error) { |
| 52 | if remainingRetries <= 0 { |
| 53 | return "", "", errors.New(ctx, "No retries left") |
| 54 | } |
| 55 | |
| 56 | password, confirmedPassword, err := askForPassword(ctx) |
| 57 | if err != nil { |
| 58 | return "", "", errors.Wrap(ctx, err, "ask for password") |
| 59 | } |
| 60 | |
| 61 | passwordValidation, ok := isPasswordValid(password, confirmedPassword) |
| 62 | if !ok { |
| 63 | if remainingRetries == 1 { |
| 64 | return "", "", errors.Newf(ctx, "%s. Too many retries", passwordValidation) |
| 65 | } |
| 66 | io.Error(fmt.Sprintf("%s. Remaining retries: %v", passwordValidation, remainingRetries-1)) |
| 67 | return askForPasswordWithRetry(ctx, remainingRetries-1) |
| 68 | } |
| 69 | |
| 70 | return password, confirmedPassword, nil |
| 71 | } |
| 72 | |
| 73 | func askForPassword(ctx context.Context) (string, string, error) { |
| 74 | fmt.Printf("Password (Will be generated if left empty): ") |
no test coverage detected