-
Notifications
You must be signed in to change notification settings - Fork 5
Update application command #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
402ea93
Create application command
asafgabai 81bada5
Create application command
asafgabai bb83487
Create application command
asafgabai 9a463db
Create application command
asafgabai 9f1939d
Create application command
asafgabai 9edf5a4
Create application command
asafgabai 3ef91d9
Static analysis fixes
asafgabai f2106be
Create application command
asafgabai d6552a1
Create application command
asafgabai 362f730
Create application command
asafgabai 730d870
Create application command
asafgabai 2a2d746
Update application command
asafgabai 85abb33
Update application command
asafgabai a38c311
Create application command
asafgabai 9f706be
Create application command
asafgabai f031ec9
Merge remote-tracking branch 'origin/APP-440-Create-application-descr…
asafgabai 064c2ac
Update application command
asafgabai e7f7c58
Create application command
asafgabai 2cef81c
Merge remote-tracking branch 'origin/APP-440-Create-application-descr…
asafgabai b9ec8c9
Create application command
asafgabai 0b7e0c3
Create application command
asafgabai 9a54ab8
Merge remote-tracking branch 'origin/APP-440-Create-application-descr…
asafgabai 9741a02
Update application command
asafgabai 1d39479
Merge remote-tracking branch 'origin/main' into APP-443-Update-specif…
asafgabai 89ff137
Update application command
asafgabai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| package application | ||
|
|
||
| import ( | ||
| pluginsCommon "github.com/jfrog/jfrog-cli-core/v2/plugins/common" | ||
|
|
||
| "github.com/jfrog/jfrog-cli-application/application/app" | ||
| "github.com/jfrog/jfrog-cli-application/application/commands" | ||
| "github.com/jfrog/jfrog-cli-application/application/commands/utils" | ||
| "github.com/jfrog/jfrog-cli-application/application/common" | ||
| "github.com/jfrog/jfrog-cli-application/application/model" | ||
| "github.com/jfrog/jfrog-cli-application/application/service" | ||
| "github.com/jfrog/jfrog-cli-application/application/service/applications" | ||
| commonCLiCommands "github.com/jfrog/jfrog-cli-core/v2/common/commands" | ||
| "github.com/jfrog/jfrog-cli-core/v2/plugins/components" | ||
| coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config" | ||
| ) | ||
|
|
||
| const UpdateApp = "update-app" | ||
|
|
||
| type updateAppCommand struct { | ||
| serverDetails *coreConfig.ServerDetails | ||
| applicationService applications.ApplicationService | ||
| requestBody *model.AppDescriptor | ||
| } | ||
|
|
||
| func (uac *updateAppCommand) Run() error { | ||
| ctx, err := service.NewContext(*uac.serverDetails) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return uac.applicationService.UpdateApplication(ctx, uac.requestBody) | ||
| } | ||
|
|
||
| func (uac *updateAppCommand) ServerDetails() (*coreConfig.ServerDetails, error) { | ||
| return uac.serverDetails, nil | ||
| } | ||
|
|
||
| func (uac *updateAppCommand) CommandName() string { | ||
| return UpdateApp | ||
| } | ||
|
|
||
| func (uac *updateAppCommand) buildRequestPayload(ctx *components.Context) (*model.AppDescriptor, error) { | ||
| applicationKey := ctx.Arguments[0] | ||
| applicationName := ctx.GetStringFlagValue(commands.ApplicationNameFlag) | ||
|
|
||
| businessCriticalityStr := ctx.GetStringFlagValue(commands.BusinessCriticalityFlag) | ||
| businessCriticality, err := utils.ValidateEnumFlag( | ||
| commands.BusinessCriticalityFlag, | ||
| businessCriticalityStr, | ||
| "", | ||
| model.BusinessCriticalityValues) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| maturityLevelStr := ctx.GetStringFlagValue(commands.MaturityLevelFlag) | ||
| maturityLevel, err := utils.ValidateEnumFlag( | ||
| commands.MaturityLevelFlag, | ||
| maturityLevelStr, | ||
| model.MaturityLevelUnspecified, | ||
| model.MaturityLevelValues) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| description := ctx.GetStringFlagValue(commands.DescriptionFlag) | ||
| userOwners := utils.ParseSliceFlag(ctx.GetStringFlagValue(commands.UserOwnersFlag)) | ||
| groupOwners := utils.ParseSliceFlag(ctx.GetStringFlagValue(commands.GroupOwnersFlag)) | ||
| labelsMap, err := utils.ParseMapFlag(ctx.GetStringFlagValue(commands.LabelsFlag)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &model.AppDescriptor{ | ||
| ApplicationKey: applicationKey, | ||
| ApplicationName: applicationName, | ||
| Description: description, | ||
| MaturityLevel: maturityLevel, | ||
| BusinessCriticality: businessCriticality, | ||
| Labels: labelsMap, | ||
| UserOwners: userOwners, | ||
| GroupOwners: groupOwners, | ||
| }, nil | ||
| } | ||
|
|
||
| func (uac *updateAppCommand) prepareAndRunCommand(ctx *components.Context) error { | ||
| if len(ctx.Arguments) != 1 { | ||
| return pluginsCommon.WrongNumberOfArgumentsHandler(ctx) | ||
| } | ||
|
|
||
| var err error | ||
| uac.requestBody, err = uac.buildRequestPayload(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| uac.serverDetails, err = utils.ServerDetailsByFlags(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return commonCLiCommands.Exec(uac) | ||
| } | ||
|
|
||
| func GetUpdateAppCommand(appContext app.Context) components.Command { | ||
| cmd := &updateAppCommand{ | ||
| applicationService: appContext.GetApplicationService(), | ||
| } | ||
| return components.Command{ | ||
| Name: "update", | ||
| Description: "Update an existing application", | ||
| Category: common.CategoryApplication, | ||
| Arguments: []components.Argument{ | ||
| { | ||
| Name: "application-key", | ||
| Description: "The key of the application to update", | ||
| Optional: false, | ||
| }, | ||
| }, | ||
| Flags: commands.GetCommandFlags(commands.UpdateApp), | ||
| Action: cmd.prepareAndRunCommand, | ||
| } | ||
| } |
104 changes: 104 additions & 0 deletions
104
application/commands/application/update_app_cmd_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| package application | ||
|
|
||
| import ( | ||
| "errors" | ||
| "flag" | ||
| "testing" | ||
|
|
||
| "github.com/urfave/cli" | ||
|
|
||
| "github.com/jfrog/jfrog-cli-application/application/model" | ||
| mockapps "github.com/jfrog/jfrog-cli-application/application/service/applications/mocks" | ||
| "github.com/jfrog/jfrog-cli-core/v2/plugins/components" | ||
| "github.com/jfrog/jfrog-cli-core/v2/utils/config" | ||
| "github.com/stretchr/testify/assert" | ||
| "go.uber.org/mock/gomock" | ||
| ) | ||
|
|
||
| func TestUpdateAppCommand_Run(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| defer ctrl.Finish() | ||
|
|
||
| serverDetails := &config.ServerDetails{Url: "https://example.com"} | ||
| appKey := "app-key" | ||
| requestPayload := &model.AppDescriptor{ | ||
| ApplicationKey: appKey, | ||
| ApplicationName: "app-name", | ||
| Description: "Updated description", | ||
| MaturityLevel: "production", | ||
| BusinessCriticality: "high", | ||
| Labels: map[string]string{ | ||
| "environment": "production", | ||
| "region": "us-east", | ||
| }, | ||
| UserOwners: []string{"JohnD", "Dave Rice"}, | ||
| GroupOwners: []string{"DevOps"}, | ||
| } | ||
|
|
||
| mockAppService := mockapps.NewMockApplicationService(ctrl) | ||
| mockAppService.EXPECT().UpdateApplication(gomock.Any(), requestPayload).Return(nil).Times(1) | ||
|
|
||
| cmd := &updateAppCommand{ | ||
| applicationService: mockAppService, | ||
| serverDetails: serverDetails, | ||
| requestBody: requestPayload, | ||
| } | ||
|
|
||
| err := cmd.Run() | ||
| assert.NoError(t, err) | ||
| } | ||
|
|
||
| func TestUpdateAppCommand_Run_Error(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| defer ctrl.Finish() | ||
|
|
||
| serverDetails := &config.ServerDetails{Url: "https://example.com"} | ||
| appKey := "app-key" | ||
| requestPayload := &model.AppDescriptor{ | ||
| ApplicationKey: appKey, | ||
| ApplicationName: "app-name", | ||
| Description: "Updated description", | ||
| MaturityLevel: "production", | ||
| BusinessCriticality: "high", | ||
| Labels: map[string]string{ | ||
| "environment": "production", | ||
| "region": "us-east", | ||
| }, | ||
| UserOwners: []string{"JohnD", "Dave Rice"}, | ||
| GroupOwners: []string{"DevOps"}, | ||
| } | ||
|
|
||
| mockAppService := mockapps.NewMockApplicationService(ctrl) | ||
| mockAppService.EXPECT().UpdateApplication(gomock.Any(), requestPayload).Return(errors.New("failed to update application. Status code: 500")).Times(1) | ||
|
|
||
| cmd := &updateAppCommand{ | ||
| applicationService: mockAppService, | ||
| serverDetails: serverDetails, | ||
| requestBody: requestPayload, | ||
| } | ||
|
|
||
| err := cmd.Run() | ||
| assert.Error(t, err) | ||
| assert.Equal(t, "failed to update application. Status code: 500", err.Error()) | ||
| } | ||
|
|
||
| func TestUpdateAppCommand_WrongNumberOfArguments(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| defer ctrl.Finish() | ||
| app := cli.NewApp() | ||
| set := flag.NewFlagSet("test", 0) | ||
| ctx := cli.NewContext(app, set, nil) | ||
|
|
||
| mockAppService := mockapps.NewMockApplicationService(ctrl) | ||
| cmd := &updateAppCommand{ | ||
| applicationService: mockAppService, | ||
| } | ||
|
|
||
| // Test with no arguments | ||
| context, err := components.ConvertContext(ctx) | ||
| assert.NoError(t, err) | ||
|
|
||
| err = cmd.prepareAndRunCommand(context) | ||
| assert.Error(t, err) | ||
| assert.Contains(t, err.Error(), "Wrong number of arguments") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.