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 4a3daf9 commit 535b795
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
egress-policy: audit

- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
fetch-depth: 0
- run: docker run -v $PWD:/workdir quay.io/git-chglog/git-chglog:0.15.1 --next-tag vNext --output CHANGELOG-new.md vNext..
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go 1.20
require (
github.com/gorilla/websocket v1.5.0
github.com/ilyakaznacheev/cleanenv v1.5.0
github.com/open-amt-cloud-toolkit/go-wsman-messages v1.6.0
github.com/open-amt-cloud-toolkit/go-wsman-messages v1.8.1
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.4
golang.org/x/sys v0.11.0
Expand Down
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ github.com/ilyakaznacheev/cleanenv v1.5.0 h1:0VNZXggJE2OYdXE87bfSSwGxeiGt9moSR2l
github.com/ilyakaznacheev/cleanenv v1.5.0/go.mod h1:a5aDzaJrLCQZsazHol1w8InnDcOX0OColm64SlIi6gk=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/open-amt-cloud-toolkit/go-wsman-messages v1.4.1 h1:ckU0WSsm3I1i5L2xHj1VyQp3MhNC1unQqICBfAwwLzk=
github.com/open-amt-cloud-toolkit/go-wsman-messages v1.4.1/go.mod h1:36KrOcNg+yMvv7TcNirdds8sneQQNiUzwS3zndx566w=
github.com/open-amt-cloud-toolkit/go-wsman-messages v1.4.2 h1:St6rKyMZNPWtz/nXgLc1owx5QibXtZcROOMaM8S+1gQ=
github.com/open-amt-cloud-toolkit/go-wsman-messages v1.4.2/go.mod h1:36KrOcNg+yMvv7TcNirdds8sneQQNiUzwS3zndx566w=
github.com/open-amt-cloud-toolkit/go-wsman-messages v1.5.0 h1:p73wPdG7CQGqpsLLHMZGHWNHZSL+g08HAzFrE0R1sKE=
github.com/open-amt-cloud-toolkit/go-wsman-messages v1.5.0/go.mod h1:36KrOcNg+yMvv7TcNirdds8sneQQNiUzwS3zndx566w=
github.com/open-amt-cloud-toolkit/go-wsman-messages v1.6.0 h1:lRxD1/Y8G4FoZFCGEMbU1ZZDTYsMdA4OHxSdNj5iVTo=
github.com/open-amt-cloud-toolkit/go-wsman-messages v1.6.0/go.mod h1:36KrOcNg+yMvv7TcNirdds8sneQQNiUzwS3zndx566w=
github.com/open-amt-cloud-toolkit/go-wsman-messages v1.8.1 h1:Wxm0RMEE691IMKe78kyzfrRW04wF65Hs1Rgoc0EqLlY=
github.com/open-amt-cloud-toolkit/go-wsman-messages v1.8.1/go.mod h1:36KrOcNg+yMvv7TcNirdds8sneQQNiUzwS3zndx566w=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
Expand Down
11 changes: 11 additions & 0 deletions internal/flags/deactivate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@ 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: 8 additions & 2 deletions internal/flags/deactivate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,18 @@ 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 535b795

Please sign in to comment.