Skip to content

Commit

Permalink
support regenerate platform credentials flag (#90)
Browse files Browse the repository at this point in the history
support regenerate platform credentials flag
  • Loading branch information
pavelmaliy authored Oct 29, 2020
1 parent 0baa9dc commit cefd5d0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
20 changes: 14 additions & 6 deletions internal/cmd/platform/update_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ import (
type UpdatePlatformCmd struct {
*cmd.Context

outputFormat output.Format
name string
updatedPlatform *types.Platform
outputFormat output.Format
name string
regenerateCredentials bool
updatedPlatform *types.Platform
}

// NewUpdatePlatformCmd returns new update-platform command with context
Expand All @@ -49,12 +50,14 @@ func (upc *UpdatePlatformCmd) Validate(args []string) error {

upc.name = args[0]

if len(args) < 2 {
if len(args) < 2 && !upc.regenerateCredentials {
return fmt.Errorf("nothing to update. Platform JSON is not provided")
}

if err := json.Unmarshal([]byte(args[1]), &upc.updatedPlatform); err != nil {
return fmt.Errorf("platform JSON is invalid. Reason: %s", err.Error())
if len(args) >= 2 {
if err := json.Unmarshal([]byte(args[1]), &upc.updatedPlatform); err != nil {
return fmt.Errorf("platform JSON is invalid. Reason: %s", err.Error())
}
}

return nil
Expand All @@ -71,6 +74,9 @@ func (upc *UpdatePlatformCmd) Run() error {
return fmt.Errorf("platform with name %s not found", upc.name)
}
toUpdatePlatform := toUpdatePlatforms.Platforms[0]
if upc.regenerateCredentials {
upc.Parameters.GeneralParams = append(upc.Parameters.GeneralParams, "regenerateCredentials=true")
}
result, err := upc.Client.UpdatePlatform(toUpdatePlatform.ID, upc.updatedPlatform, &upc.Parameters)
if err != nil {
return err
Expand Down Expand Up @@ -100,6 +106,8 @@ smctl update-platform platform '{"name": "new-name", "description": "new-descrip
RunE: cmd.RunE(upc),
}

result.Flags().BoolVarP(&upc.regenerateCredentials, "regenerate-credentials", "c", false, "Whether to regenerate credentials")

cmd.AddFormatFlag(result.Flags())
cmd.AddCommonQueryFlag(result.Flags(), &upc.Parameters)

Expand Down
9 changes: 9 additions & 0 deletions internal/cmd/platform/update_platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ var _ = Describe("Update platform command test", func() {
Expect(args.LabelQuery).To(BeEmpty())
})
})

Context("With regenerate-credentials flag", func() {
It("platform should pass it to SM", func() {
validUpdatePlatformExecution("platform", "--regenerate-credentials")

_, _, args := client.UpdatePlatformArgsForCall(0)
Expect(args.GeneralParams).To(ConsistOf("regenerateCredentials=true"))
})
})
})

Describe("Invalid request", func() {
Expand Down

0 comments on commit cefd5d0

Please sign in to comment.