Skip to content

Commit

Permalink
feat: Add password prompt for local activation
Browse files Browse the repository at this point in the history
  • Loading branch information
zaidusmani26 committed Sep 5, 2023
1 parent 09fdd03 commit 6cdfa31
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 12 additions & 0 deletions internal/flags/deactivate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@ package flags
import (
"fmt"
"rpc/pkg/utils"

log "github.com/sirupsen/logrus"
)

func (f *Flags) handleDeactivateCommand() int {
f.amtDeactivateCommand.BoolVar(&f.Local, "local", false, "Execute command to AMT directly without cloud interaction")

if len(f.commandLineArgs) == 3 && f.commandLineArgs[2] == "-local" {
_, errCode := f.ReadPasswordFromUser()
if f.Password == "" {
if errCode != 0 {
log.Error("Please enter value for AMT Password")
return utils.MissingOrIncorrectPassword
}
}
}
if len(f.commandLineArgs) == 2 {
f.amtDeactivateCommand.PrintDefaults()
return utils.IncorrectCommandLineParameters
Expand Down
10 changes: 9 additions & 1 deletion internal/flags/deactivate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,20 @@ func TestHandleDeactivateCommandWithForce(t *testing.T) {
}

func TestHandleLocalDeactivation(t *testing.T) {
args := []string{"./rpc", "deactivate", "-local"}
args := []string{"./rpc", "deactivate", "-local", "password"}
flags := NewFlags(args)
errCode := flags.ParseFlags()
assert.Equal(t, errCode, utils.Success)
}

func TestParseFlagsDeactivateNoPassword(t *testing.T) {
args := []string{"./rpc", "deactivate", "-local"}
flags := NewFlags(args)
result := flags.ParseFlags()
assert.EqualValues(t, result, utils.MissingOrIncorrectPassword)
assert.Equal(t, utils.CommandDeactivate, flags.Command)
}

func TestParseFlagsDeactivate(t *testing.T) {
args := []string{"./rpc", "deactivate"}
flags := NewFlags(args)
Expand Down

0 comments on commit 6cdfa31

Please sign in to comment.