func()

in internal/command/twofactorverify/twofactorverify.go [31:74]


func (c *Command) Execute(ctx context.Context) (context.Context, error) {
	client, err := twofactorverify.NewClient(c.Config)
	if err != nil {
		return ctx, err
	}

	ctx, cancel := context.WithTimeout(ctx, timeout)
	defer cancel()

	_, _ = fmt.Fprint(c.ReadWriter.Out, prompt)

	resultCh := make(chan string)
	go func() {
		err := client.PushAuth(ctx, c.Args)
		if err == nil {
			resultCh <- "OTP has been validated by Push Authentication. Git operations are now allowed."
		}
	}()

	go func() {
		answer, err := c.getOTP(ctx)
		if err != nil {
			resultCh <- formatErr(err)
		}

		if err := client.VerifyOTP(ctx, c.Args, answer); err != nil {
			resultCh <- formatErr(err)
		} else {
			resultCh <- "OTP validation successful. Git operations are now allowed."
		}
	}()

	var message string
	select {
	case message = <-resultCh:
	case <-ctx.Done():
		message = formatErr(ctx.Err())
	}

	log.WithContextFields(ctx, log.Fields{"message": message}).Info("Two factor verify command finished")
	_, _ = fmt.Fprintf(c.ReadWriter.Out, "\n%v\n", message)

	return ctx, nil
}