From 535b79598845a4083c8c4e1000c03ea16ba7e8d6 Mon Sep 17 00:00:00 2001 From: zaidusmani26 Date: Mon, 4 Sep 2023 19:59:01 -0700 Subject: [PATCH] feat: Add password prompt for local activation --- .github/workflows/changelog.yml | 2 +- go.mod | 2 +- go.sum | 10 ++-------- internal/flags/deactivate.go | 11 +++++++++++ internal/flags/deactivate_test.go | 10 ++++++++-- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 6f1989f9..e95f77e5 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -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.. diff --git a/go.mod b/go.mod index b1baeb4f..7dd1102a 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index e381a25d..90081aa4 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/flags/deactivate.go b/internal/flags/deactivate.go index 58828b63..337acb1e 100644 --- a/internal/flags/deactivate.go +++ b/internal/flags/deactivate.go @@ -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 diff --git a/internal/flags/deactivate_test.go b/internal/flags/deactivate_test.go index 00f22822..aa9b16a9 100644 --- a/internal/flags/deactivate_test.go +++ b/internal/flags/deactivate_test.go @@ -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)