As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit eb6033a6 authored by James Sandlin's avatar James Sandlin
Browse files

close; things are colliding

parent 1fa30cb0
No related branches found
No related tags found
No related merge requests found
Pipeline #63400 failed
Loading
Loading
@@ -34,107 +34,6 @@ var (
ctxMaxTime = time.Second + 30
)
func (c *Command) Execute2(ctx context.Context) error {
ctxlog := log.ContextLogger(ctx)
// config.GetHTTPClient isn't thread-safe so save Client in struct for concurrency
// workaround until #518 is fixed
var err error
c.Client, err = twofactorverify.NewClient(c.Config)
fmt.Println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
fmt.Println("client = ", c.Client)
fmt.Println("err = ", err)
fmt.Println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
if err != nil {
ctxlog.WithError(err).Error("twofactorverify: execute: OTP verification failed")
return err
}
// Create timeout context
// TODO: make timeout configurable
const ctxTimeout = 30
timeoutCtx, cancelTimeout := context.WithTimeout(ctx, ctxTimeout*time.Second)
verifyCtx, cancelVerify := context.WithCancel(timeoutCtx)
pushCtx, cancelPush := context.WithCancel(timeoutCtx)
defer cancelTimeout()
//fmt.Println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
//fmt.Println(verifyCtx, ", ", cancelVerify)
//fmt.Println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
// Background push notification with timeout
pushauth := make(chan Result)
go func() {
defer close(pushauth)
status, success, err := c.pushAuth(pushCtx)
select {
case <-pushCtx.Done(): // push cancelled by manual OTP
pushauth <- Result{Error: nil, Status: "cancelled", Success: false}
default:
pushauth <- Result{Error: err, Status: status, Success: success}
cancelVerify()
}
}()
// Also allow manual OTP entry while waiting for push, with same timeout as push
verify := make(chan Result)
go func() {
defer close(verify)
ctxlog.Info("twofactorverify: execute: waiting for user input")
answer := ""
answer = c.getOTP(verifyCtx)
select {
case <-verifyCtx.Done(): // manual OTP cancelled by push
verify <- Result{Error: nil, Status: "cancelled", Success: false}
default:
cancelPush()
ctxlog.Info("twofactorverify: execute: verifying entered OTP")
status, success, err := c.verifyOTP(verifyCtx, answer)
//fmt.Println("-------------")
//fmt.Println("pushAuth.status = ", status)
//fmt.Println("pushAuth.success = ", success)
//fmt.Println("pushAuth.err = ", err)
//fmt.Println("-------------")
ctxlog.WithError(err).Info("twofactorverify: execute: OTP verified")
verify <- Result{Error: err, Status: status, Success: success}
}
}()
for {
select {
case res := <-verify: // manual OTP
//fmt.Println("-------------")
//fmt.Println("verify.res = ", res)
//fmt.Println("-------------")
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
//fmt.Println("-------------")
//fmt.Println("pushauth.res = ", res)
//fmt.Println("-------------")
if res.Status == "cancelled" {
// push 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 <-timeoutCtx.Done(): // push timed out
fmt.Fprint(c.ReadWriter.Out, "\nOTP verification timed out\n")
return nil
}
}
return nil
}
func (c *Command) Execute(ctx context.Context) error {
ctxlog := log.ContextLogger(ctx)
Loading
Loading
@@ -154,6 +53,8 @@ func (c *Command) Execute(ctx context.Context) error {
defer cancelCtx()
//myctx, mycancel := context.WithCancel(timeoutCtx)
myctx2, cancelCtx2 := context.WithTimeout(ctx, ctxMaxTime)
defer cancelCtx2()
// Also allow manual OTP entry while waiting for push, with same timeout as push
Loading
Loading
@@ -182,44 +83,41 @@ func (c *Command) Execute(ctx context.Context) error {
defer waitGroup.Done()
//defer close(pushChannel)
ctxlog.Info("twofactorverify: execute: waiting for push auth")
//status, success, err := c.pushAuth(myctx)
//ctxlog.WithError(err).Info("twofactorverify: execute: push auth verified")
ctxlog.WithError(err).Info("twofactorverify: execute: push auth verified")
select {
case <-myctx.Done(): // push cancelled by manual OTP
case <-myctx2.Done(): // push cancelled by manual OTP
// skip writing to channel
pushChannel <- Result{Error: nil, Status: "cancelled", Success: false}
ctxlog.Info("twofactorverify: execute: push auth cancelled")
//default:
// pushChannel <- Result{Error: err, Status: status, Success: success}
default:
status, success, err := c.pushAuth(myctx2)
pushChannel <- Result{Error: err, Status: status, Success: success}
}
}()
//for {
select {
case res := <-otpChannel:
//fmt.Println("Received from otpChannel => ", res)
if len(res.Status) > 0 && res.Status != "cancelled" {
fmt.Fprint(c.ReadWriter.Out, res.Status)
return nil
}
case res := <-pushChannel:
if len(res.Status) > 0 && res.Status != "cancelled" {
//fmt.Println("Received from pushChannel => ", res)
fmt.Println("res.Status == ", res.Status, " -> ", len(res.Status))
// //fmt.Println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
// //fmt.Println(res)
// //fmt.Println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
fmt.Fprint(c.ReadWriter.Out, res.Status)
return nil
}
//case <- myctx.Done():
// fmt.Fprint(c.ReadWriter.Out, "\nOTP verification timed out\n")
// return nil
}
select {
case res := <-otpChannel:
//fmt.Println("Received from otpChannel => ", res)
if len(res.Status) > 0 && res.Status != "cancelled" {
fmt.Fprint(c.ReadWriter.Out, res.Status)
return nil
}
case res := <-pushChannel:
if len(res.Status) > 0 && res.Status != "cancelled" {
//fmt.Println("Received from pushChannel => ", res)
fmt.Println("res.Status == ", res.Status, " -> ", len(res.Status))
fmt.Fprint(c.ReadWriter.Out, res.Status)
return nil
}
case <- myctx.Done():
fmt.Fprint(c.ReadWriter.Out, "\nOTP verification timed out\n")
return nil
}
waitGroup.Wait()
//}
return nil
}
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment