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 7bc39224 authored by Igor Drozdov's avatar Igor Drozdov
Browse files

Handle and log unhandled errors

Currently, we don't process the results of this execution,
because it's not really imprortant

Let's at least log the err if the execution went wrong

That will also make Vulnerability report happy
parent 2b93e5a1
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -26,7 +26,7 @@ func (c *Command) Execute(ctx context.Context) error {
ctxlog := log.ContextLogger(ctx)
ctxlog.Debug("twofactorrecover: execute: Waiting for user input")
if c.canContinue() {
if c.getUserAnswer(ctx) == "yes" {
ctxlog.Debug("twofactorrecover: execute: User chose to continue")
c.displayRecoveryCodes(ctx)
} else {
Loading
Loading
@@ -37,16 +37,18 @@ func (c *Command) Execute(ctx context.Context) error {
return nil
}
func (c *Command) canContinue() bool {
func (c *Command) getUserAnswer(ctx context.Context) string {
question :=
"Are you sure you want to generate new two-factor recovery codes?\n" +
"Any existing recovery codes you saved will be invalidated. (yes/no)"
fmt.Fprintln(c.ReadWriter.Out, question)
var answer string
fmt.Fscanln(io.LimitReader(c.ReadWriter.In, readerLimit), &answer)
if _, err := fmt.Fscanln(io.LimitReader(c.ReadWriter.In, readerLimit), &answer); err != nil {
log.ContextLogger(ctx).WithError(err).Debug("twofactorrecover: getUserAnswer: Failed to get user input")
}
return answer == "yes"
return answer
}
func (c *Command) displayRecoveryCodes(ctx context.Context) {
Loading
Loading
Loading
Loading
@@ -22,7 +22,7 @@ type Command struct {
func (c *Command) Execute(ctx context.Context) error {
ctxlog := log.ContextLogger(ctx)
ctxlog.Info("twofactorverify: execute: waiting for user input")
otp := c.getOTP()
otp := c.getOTP(ctx)
ctxlog.Info("twofactorverify: execute: verifying entered OTP")
err := c.verifyOTP(ctx, otp)
Loading
Loading
@@ -35,14 +35,16 @@ func (c *Command) Execute(ctx context.Context) error {
return nil
}
func (c *Command) getOTP() string {
func (c *Command) getOTP(ctx context.Context) string {
prompt := "OTP: "
fmt.Fprint(c.ReadWriter.Out, prompt)
var answer string
otpLength := int64(64)
reader := io.LimitReader(c.ReadWriter.In, otpLength)
fmt.Fscanln(reader, &answer)
if _, err := fmt.Fscanln(reader, &answer); err != nil {
log.ContextLogger(ctx).WithError(err).Debug("twofactorverify: getOTP: Failed to get user input")
}
return answer
}
Loading
Loading
Loading
Loading
@@ -66,8 +66,11 @@ func (s *session) handle(ctx context.Context, requests <-chan *ssh.Request) {
default:
// Ignore unknown requests but don't terminate the session
shouldContinue = true
if req.WantReply {
req.Reply(false, []byte{})
if err := req.Reply(false, []byte{}); err != nil {
sessionLog.WithError(err).Debug("session: handle: Failed to reply")
}
}
}
Loading
Loading
@@ -100,7 +103,9 @@ func (s *session) handleEnv(ctx context.Context, req *ssh.Request) bool {
}
if req.WantReply {
req.Reply(accepted, []byte{})
if err := req.Reply(accepted, []byte{}); err != nil {
log.ContextLogger(ctx).WithError(err).Debug("session: handleEnv: Failed to reply")
}
}
log.WithContextFields(
Loading
Loading
@@ -124,8 +129,12 @@ func (s *session) handleExec(ctx context.Context, req *ssh.Request) bool {
}
func (s *session) handleShell(ctx context.Context, req *ssh.Request) uint32 {
ctxlog := log.ContextLogger(ctx)
if req.WantReply {
req.Reply(true, []byte{})
if err := req.Reply(true, []byte{}); err != nil {
ctxlog.WithError(err).Debug("session: handleShell: Failed to reply")
}
}
env := sshenv.Env{
Loading
Loading
@@ -151,7 +160,6 @@ func (s *session) handleShell(ctx context.Context, req *ssh.Request) uint32 {
}
cmdName := reflect.TypeOf(cmd).String()
ctxlog := log.ContextLogger(ctx)
ctxlog.WithFields(log.Fields{"env": env, "command": cmdName}).Info("session: handleShell: executing command")
if err := cmd.Execute(ctx); err != 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