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

Passing pushauth flag as bool in json body to internal api doesn't become a...

Open Manoj Memana Jayakumar requested to merge mmj/gitlab-shell:506-jsandlin into main
2 files
+ 99
23
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -17,12 +17,44 @@ type Command struct {
ReadWriter *readwriter.ReadWriter
}
type Result struct {
Error error
Status string
Success bool
}
func (c *Command) Execute(ctx context.Context) error {
err := c.verifyOTP(ctx, c.getOTP())
if err != nil {
return err
}
verify := make(chan Result)
pushauth := make(chan Result)
go func() {
status, success, err := c.verifyOTP(ctx, c.getOTP())
verify <- Result{Error: err, Status: status, Success: success}
}()
go func() {
status, success, err := c.pushAuth(ctx)
pushauth <- Result{Error: err, Status: status, Success: success}
}()
L:
for {
select {
case res := <-verify:
if res.Error != nil {
return res.Error
}
fmt.Fprint(c.ReadWriter.Out, res.Status)
break L
case res := <-pushauth:
if res.Success {
fmt.Fprint(c.ReadWriter.Out, res.Status)
break L
} else {
// ignore reject from remote, need to wait for user input in this case
}
}
}
return nil
}
@@ -38,18 +70,46 @@ func (c *Command) getOTP() string {
return answer
}
func (c *Command) verifyOTP(ctx context.Context, otp string) error {
func (c *Command) pushAuth(ctx context.Context) (status string, success bool, err error) {
client, err := twofactorverify.NewClient(c.Config)
if err != nil {
return err
return "", false, err
}
err = client.VerifyOTP(ctx, c.Args, otp)
if err == nil {
fmt.Fprint(c.ReadWriter.Out, "\nOTP validation successful. Git operations are now allowed.\n")
reason := ""
success, reason, err = client.PushAuth(ctx, c.Args)
if success {
status = fmt.Sprintf("\nPush OTP validation successful. Git operations are now allowed.\n")
} else {
fmt.Fprintf(c.ReadWriter.Out, "\nOTP validation failed.\n%v\n", err)
if err != nil {
status = fmt.Sprintf("\nPush OTP validation failed.\n%v\n", err)
} else {
status = fmt.Sprintf("\nPush OTP validation failed.\n%v\n", reason)
}
}
return nil
return
}
func (c *Command) verifyOTP(ctx context.Context, otp string) (status string, success bool, err error) {
client, err := twofactorverify.NewClient(c.Config)
if err != nil {
return "", false, err
}
reason := ""
success, reason, err = client.VerifyOTP(ctx, c.Args, otp)
if success {
status = fmt.Sprintf("\nOTP validation successful. Git operations are now allowed.\n")
} else {
if err != nil {
status = fmt.Sprintf("\nOTP validation failed.\n%v\n", err)
} else {
status = fmt.Sprintf("\nOTP validation failed.\n%v\n", reason)
}
}
return
}
Loading