summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkmcknight <kmcknight@gitlab.com>2022-07-12 18:03:09 -0700
committerkmcknight <kmcknight@gitlab.com>2022-07-12 18:03:09 -0700
commit9b2246d8daa9f8b70dd5e8ed92179c6593b8708c (patch)
treefe4bd018dda2e1b8c4851f8e39f13012666fba23
parentaac413ea1e1a7074b2c52431b67df215e2c929ba (diff)
downloadgitlab-shell-9b2246d8daa9f8b70dd5e8ed92179c6593b8708c.tar.gz
Remove redundant channel
-rw-r--r--internal/command/twofactorverify/twofactorverify.go30
1 files changed, 11 insertions, 19 deletions
diff --git a/internal/command/twofactorverify/twofactorverify.go b/internal/command/twofactorverify/twofactorverify.go
index c9c0462..bc7123b 100644
--- a/internal/command/twofactorverify/twofactorverify.go
+++ b/internal/command/twofactorverify/twofactorverify.go
@@ -46,55 +46,47 @@ func (c *Command) Execute(ctx context.Context) error {
timeoutCtx, cancelTimeout := context.WithTimeout(ctx, ctxTimeout*time.Second)
defer cancelTimeout()
+ // Create result channel
+ resultC := make(chan Result)
+
// Background push notification with timeout
- pushauth := make(chan Result)
go func() {
- defer close(pushauth)
+ defer close(resultC)
status, success, err := c.pushAuth(timeoutCtx)
select {
case <-timeoutCtx.Done(): // push cancelled by manual OTP
- pushauth <- Result{Error: nil, Status: "cancelled", Success: false}
+ resultC <- Result{Error: nil, Status: "cancelled", Success: false}
default:
- pushauth <- Result{Error: err, Status: status, Success: success}
+ resultC <- Result{Error: err, Status: status, Success: success}
cancelTimeout()
}
}()
// Also allow manual OTP entry while waiting for push, with same timeout as push
- verify := make(chan Result)
go func() {
- defer close(verify)
+ defer close(resultC)
ctxlog.Info("twofactorverify: execute: waiting for user input")
answer := ""
answer = c.getOTP(timeoutCtx)
select {
case <-timeoutCtx.Done(): // manual OTP cancelled by push
- verify <- Result{Error: nil, Status: "cancelled", Success: false}
+ resultC <- Result{Error: nil, Status: "cancelled", Success: false}
default:
cancelTimeout()
ctxlog.Info("twofactorverify: execute: verifying entered OTP")
status, success, err := c.verifyOTP(timeoutCtx, answer)
ctxlog.WithError(err).Info("twofactorverify: execute: OTP verified")
- verify <- Result{Error: err, Status: status, Success: success}
+ resultC <- Result{Error: err, Status: status, Success: success}
}
}()
for {
select {
- case res := <-verify: // manual OTP
- if res.Status == "cancelled" {
- // verify cancelled; don't print anything
- } else if res.Status == "" {
- // channel closed; don't print anything
- } else {
- fmt.Fprint(c.ReadWriter.Out, res.Status)
- return nil
- }
- case res := <-pushauth: // push
+ case res := <-resultC:
if res.Status == "cancelled" {
- // push cancelled; don't print anything
+ // request cancelled; don't print anything
} else if res.Status == "" {
// channel closed; don't print anything
} else {