|
| 1 | +package version |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "github.com/jfrog/jfrog-cli-application/application/app" |
| 6 | + "github.com/jfrog/jfrog-cli-application/application/commands" |
| 7 | + "github.com/jfrog/jfrog-cli-application/application/common" |
| 8 | + "github.com/jfrog/jfrog-cli-application/application/model" |
| 9 | + "github.com/jfrog/jfrog-cli-application/application/service" |
| 10 | + commonCliUtils "github.com/jfrog/jfrog-cli-core/v2/common/cliutils" |
| 11 | + commonCLiCommands "github.com/jfrog/jfrog-cli-core/v2/common/commands" |
| 12 | + pluginsCommon "github.com/jfrog/jfrog-cli-core/v2/plugins/common" |
| 13 | + "github.com/jfrog/jfrog-cli-core/v2/plugins/components" |
| 14 | + coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config" |
| 15 | +) |
| 16 | + |
| 17 | +type createAppVersionCommand struct { |
| 18 | + versionService service.VersionService |
| 19 | + serverDetails *coreConfig.ServerDetails |
| 20 | + requestPayload *model.CreateAppVersionRequest |
| 21 | +} |
| 22 | + |
| 23 | +func (cv *createAppVersionCommand) Run() error { |
| 24 | + ctx := &service.Context{ServerDetails: cv.serverDetails} |
| 25 | + return cv.versionService.CreateAppVersion(ctx, cv.requestPayload) |
| 26 | +} |
| 27 | + |
| 28 | +func (cv *createAppVersionCommand) ServerDetails() (*coreConfig.ServerDetails, error) { |
| 29 | + return cv.serverDetails, nil |
| 30 | +} |
| 31 | + |
| 32 | +func (cv *createAppVersionCommand) CommandName() string { |
| 33 | + return commands.CreateAppVersion |
| 34 | +} |
| 35 | + |
| 36 | +func (cv *createAppVersionCommand) runCreateAppVersionCommand(ctx *components.Context) error { |
| 37 | + if err := validateCreateAppVersionContext(ctx); err != nil { |
| 38 | + return err |
| 39 | + } |
| 40 | + serverDetails, err := serverDetailsByFlags(ctx) |
| 41 | + if err != nil { |
| 42 | + return err |
| 43 | + } |
| 44 | + cv.serverDetails = serverDetails |
| 45 | + cv.requestPayload = &model.CreateAppVersionRequest{} |
| 46 | + return commonCLiCommands.Exec(cv) |
| 47 | +} |
| 48 | + |
| 49 | +func serverDetailsByFlags(ctx *components.Context) (*coreConfig.ServerDetails, error) { |
| 50 | + serverDetails, err := pluginsCommon.CreateServerDetailsWithConfigOffer(ctx, true, commonCliUtils.Platform) |
| 51 | + if err != nil { |
| 52 | + return nil, err |
| 53 | + } |
| 54 | + if serverDetails.Url == "" { |
| 55 | + return nil, errors.New("platform URL is mandatory for evidence commands") |
| 56 | + } |
| 57 | + if serverDetails.GetUser() != "" && serverDetails.GetPassword() != "" { |
| 58 | + return nil, errors.New("evidence service does not support basic authentication") |
| 59 | + } |
| 60 | + |
| 61 | + return serverDetails, nil |
| 62 | +} |
| 63 | + |
| 64 | +func validateCreateAppVersionContext(ctx *components.Context) error { |
| 65 | + if show, err := pluginsCommon.ShowCmdHelpIfNeeded(ctx, ctx.Arguments); show || err != nil { |
| 66 | + return err |
| 67 | + } |
| 68 | + if len(ctx.Arguments) > 1 { |
| 69 | + return pluginsCommon.WrongNumberOfArgumentsHandler(ctx) |
| 70 | + } |
| 71 | + |
| 72 | + return nil |
| 73 | + //err := utils.AssertValueProvided(ctx, commands.PackageNameFlag) |
| 74 | + //if err != nil { |
| 75 | + // return err |
| 76 | + //} |
| 77 | + //err = utils.AssertValueProvided(ctx, commands.PackageVersionFlag) |
| 78 | + //if err != nil { |
| 79 | + // return err |
| 80 | + //} |
| 81 | + //err = utils.AssertValueProvided(ctx, commands.PackageRepoNameFlag) |
| 82 | + //return err |
| 83 | +} |
| 84 | + |
| 85 | +func GetCreateAppVersionCommand(appContext app.Context) components.Command { |
| 86 | + cmd := &createAppVersionCommand{versionService: appContext.GetVersionService()} |
| 87 | + return components.Command{ |
| 88 | + Name: commands.CreateAppVersion, |
| 89 | + Description: "Create application version", |
| 90 | + Category: common.CategoryVersion, |
| 91 | + Aliases: []string{"cav"}, |
| 92 | + Arguments: []components.Argument{}, |
| 93 | + Flags: commands.GetCommandFlags(commands.CreateAppVersion), |
| 94 | + Action: cmd.runCreateAppVersionCommand, |
| 95 | + } |
| 96 | +} |
0 commit comments