summaryrefslogtreecommitdiff
path: root/internal/command
diff options
context:
space:
mode:
authorIgor Drozdov <idrozdov@gitlab.com>2022-02-01 11:39:40 +0300
committerIgor Drozdov <idrozdov@gitlab.com>2022-02-02 14:44:34 +0300
commit7bc39224b224d98b31dfd244aec1708d8d2db286 (patch)
treeec240adc83749d2318ae6364565148fc58f2e191 /internal/command
parent2b93e5a1f048d11df85fc96498101449e1704294 (diff)
downloadgitlab-shell-7bc39224b224d98b31dfd244aec1708d8d2db286.tar.gz
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
Diffstat (limited to 'internal/command')
-rw-r--r--internal/command/twofactorrecover/twofactorrecover.go10
-rw-r--r--internal/command/twofactorverify/twofactorverify.go8
2 files changed, 11 insertions, 7 deletions
diff --git a/internal/command/twofactorrecover/twofactorrecover.go b/internal/command/twofactorrecover/twofactorrecover.go
index 91eca3a..6982689 100644
--- a/internal/command/twofactorrecover/twofactorrecover.go
+++ b/internal/command/twofactorrecover/twofactorrecover.go
@@ -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 {
@@ -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) {
diff --git a/internal/command/twofactorverify/twofactorverify.go b/internal/command/twofactorverify/twofactorverify.go
index fe17339..0099e84 100644
--- a/internal/command/twofactorverify/twofactorverify.go
+++ b/internal/command/twofactorverify/twofactorverify.go
@@ -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)
@@ -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
}