Skip to content

Commit 044ec29

Browse files
committed
Added promote application version command
1 parent a51ca06 commit 044ec29

File tree

8 files changed

+250
-133
lines changed

8 files changed

+250
-133
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ prereq::
4949
GOBIN=${TOOLS_DIR} $(GOCMD) install go.uber.org/mock/[email protected]
5050

5151
build::
52-
go env GOOS GOARCH
53-
go build -ldflags="${LINKERFLAGS}" -gcflags ${COMPILERFLAGS} -o ${BINARY_CLI}/application-cli-plugin main.go
52+
$(GOCMD) env GOOS GOARCH
53+
$(GOCMD) build -ldflags="${LINKERFLAGS}" -gcflags ${COMPILERFLAGS} -o ${BINARY_CLI}/application-cli-plugin main.go
5454

5555

5656
build-install:: build

application/cli/cli.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
88
)
99

10-
const category = "Application Lifecycle"
11-
10+
//const category = "Application Lifecycle"
11+
//
1212
//
1313
//func GetJfrogApplicationCli() components.App {
1414
// appContext := app.NewAppContext()
@@ -32,11 +32,12 @@ func GetJfrogApplicationCli() components.App {
3232
appContext := app.NewAppContext()
3333
appEntity := components.CreateApp(
3434
"app",
35-
"1.0.0",
35+
"1.0.2",
3636
"JFrog Application CLI",
3737
[]components.Command{
3838
system.GetPingCommand(appContext),
3939
version.GetCreateAppVersionCommand(appContext),
40+
version.GetPromoteAppVersionCommand(appContext),
4041
},
4142
)
4243
return appEntity

application/commands/flags.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import pluginsCommon "github.com/jfrog/jfrog-cli-core/v2/plugins/common"
44
import "github.com/jfrog/jfrog-cli-core/v2/plugins/components"
55

66
const (
7-
Ping = "ping"
8-
CreateAppVersion = "create-app-version"
7+
Ping = "ping"
8+
CreateAppVersion = "create-app-version"
9+
PromoteAppVersion = "promote-app-version"
910
)
1011

1112
const (
@@ -22,6 +23,7 @@ const (
2223
PackageRepositoryFlag = "package-repository"
2324
SpecFlag = "spec"
2425
SpecVarsFlag = "spec-vars"
26+
EnvironmentVarsFlag = "env"
2527
)
2628

2729
// Flag keys mapped to their corresponding components.Flag definition.
@@ -40,6 +42,7 @@ var flagsMap = map[string]components.Flag{
4042
PackageRepositoryFlag: components.NewStringFlag(PackageRepositoryFlag, "Package storing repository.", func(f *components.StringFlag) { f.Mandatory = false }),
4143
SpecFlag: components.NewStringFlag(SpecFlag, "A path to the specification file.", func(f *components.StringFlag) { f.Mandatory = false }),
4244
SpecVarsFlag: components.NewStringFlag(SpecVarsFlag, "List of semicolon-separated(;) variables in the form of \"key1=value1;key2=value2;...\" (wrapped by quotes) to be replaced in the File Spec. In the File Spec, the variables should be used as follows: ${key1}.` `", func(f *components.StringFlag) { f.Mandatory = false }),
45+
EnvironmentVarsFlag: components.NewStringFlag(EnvironmentVarsFlag, "Environment.", func(f *components.StringFlag) { f.Mandatory = true }),
4346
}
4447

4548
var commandFlags = map[string][]string{
@@ -57,6 +60,15 @@ var commandFlags = map[string][]string{
5760
SpecFlag,
5861
SpecVarsFlag,
5962
},
63+
PromoteAppVersion: {
64+
url,
65+
user,
66+
accessToken,
67+
ServerId,
68+
ProjectFlag,
69+
ApplicationKeyFlag,
70+
EnvironmentVarsFlag,
71+
},
6072

6173
Ping: {
6274
url,
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package version
2+
3+
import (
4+
"github.com/jfrog/jfrog-cli-application/application/app"
5+
"github.com/jfrog/jfrog-cli-application/application/commands"
6+
"github.com/jfrog/jfrog-cli-application/application/commands/utils"
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+
commonCLiCommands "github.com/jfrog/jfrog-cli-core/v2/common/commands"
11+
pluginsCommon "github.com/jfrog/jfrog-cli-core/v2/plugins/common"
12+
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
13+
coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
14+
"github.com/jfrog/jfrog-client-go/utils/errorutils"
15+
)
16+
17+
type promoteAppVersionCommand struct {
18+
versionService service.VersionService
19+
serverDetails *coreConfig.ServerDetails
20+
requestPayload *model.PromoteAppVersionRequest
21+
}
22+
23+
func (pv *promoteAppVersionCommand) Run() error {
24+
ctx := &service.Context{ServerDetails: pv.serverDetails}
25+
return pv.versionService.PromoteAppVersion(ctx, pv.requestPayload)
26+
}
27+
28+
func (pv *promoteAppVersionCommand) ServerDetails() (*coreConfig.ServerDetails, error) {
29+
return pv.serverDetails, nil
30+
}
31+
32+
func (pv *promoteAppVersionCommand) CommandName() string {
33+
return commands.PromoteAppVersion
34+
}
35+
36+
func (pv *promoteAppVersionCommand) prepareAndRunCommand(ctx *components.Context) error {
37+
if err := validatePromoteAppVersionContext(ctx); err != nil {
38+
return err
39+
}
40+
serverDetails, err := utils.ServerDetailsByFlags(ctx)
41+
if err != nil {
42+
return err
43+
}
44+
pv.serverDetails = serverDetails
45+
pv.requestPayload, err = pv.buildRequestPayload(ctx)
46+
if errorutils.CheckError(err) != nil {
47+
return err
48+
}
49+
return commonCLiCommands.Exec(pv)
50+
}
51+
52+
func validatePromoteAppVersionContext(ctx *components.Context) error {
53+
if show, err := pluginsCommon.ShowCmdHelpIfNeeded(ctx, ctx.Arguments); show || err != nil {
54+
return err
55+
}
56+
if len(ctx.Arguments) != 1 {
57+
return pluginsCommon.WrongNumberOfArgumentsHandler(ctx)
58+
}
59+
return nil
60+
}
61+
62+
func (pv *promoteAppVersionCommand) buildRequestPayload(ctx *components.Context) (*model.PromoteAppVersionRequest, error) {
63+
return &model.PromoteAppVersionRequest{
64+
ApplicationKey: ctx.GetStringFlagValue(commands.ApplicationKeyFlag),
65+
Version: ctx.Arguments[0],
66+
Environment: ctx.GetStringFlagValue(commands.EnvironmentVarsFlag),
67+
}, nil
68+
}
69+
70+
func GetPromoteAppVersionCommand(appContext app.Context) components.Command {
71+
cmd := &promoteAppVersionCommand{versionService: appContext.GetVersionService()}
72+
return components.Command{
73+
Name: commands.PromoteAppVersion,
74+
Description: "Promote application version",
75+
Category: common.CategoryVersion,
76+
Aliases: []string{"pav"},
77+
Arguments: []components.Argument{
78+
{
79+
Name: "version-name",
80+
Description: "The name of the version",
81+
Optional: false,
82+
},
83+
},
84+
Flags: commands.GetCommandFlags(commands.PromoteAppVersion),
85+
Action: cmd.prepareAndRunCommand,
86+
}
87+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package model
2+
3+
type PromoteAppVersionRequest struct {
4+
ApplicationKey string `json:"application_key"`
5+
Version string `json:"version"`
6+
Environment string `json:"environment"`
7+
}

application/service/version_service.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
type VersionService interface {
1010
CreateAppVersion(ctx *Context, request *model.CreateAppVersionRequest) error
11+
PromoteAppVersion(ctx *Context, payload *model.PromoteAppVersionRequest) error
1112
}
1213

1314
type versionService struct {
@@ -35,3 +36,22 @@ func (vs *versionService) CreateAppVersion(ctx *Context, request *model.CreateAp
3536

3637
return nil
3738
}
39+
40+
func (vs *versionService) PromoteAppVersion(ctx *Context, payload *model.PromoteAppVersionRequest) error {
41+
httpClient, err := http.NewAppHttpClient(ctx.ServerDetails)
42+
if err != nil {
43+
return err
44+
}
45+
46+
response, responseBody, err := httpClient.Post("/v1/version/promote", payload)
47+
if err != nil {
48+
return err
49+
}
50+
51+
if response.StatusCode >= 400 {
52+
return fmt.Errorf("failed to promote app version. Status code: %d. \n%s",
53+
response.StatusCode, responseBody)
54+
}
55+
56+
return nil
57+
}

go.mod

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,87 +3,87 @@ module github.com/jfrog/jfrog-cli-application
33
go 1.23.4
44

55
require (
6-
github.com/jfrog/jfrog-cli-core/v2 v2.57.5
7-
github.com/jfrog/jfrog-client-go v1.48.6
6+
github.com/jfrog/jfrog-cli-core/v2 v2.57.6
7+
github.com/jfrog/jfrog-client-go v1.49.0
88
)
99

1010
require (
11-
dario.cat/mergo v1.0.0 // indirect
11+
dario.cat/mergo v1.0.1 // indirect
1212
github.com/BurntSushi/toml v1.4.0 // indirect
13-
github.com/CycloneDX/cyclonedx-go v0.9.0 // indirect
14-
github.com/Microsoft/go-winio v0.6.1 // indirect
15-
github.com/ProtonMail/go-crypto v1.1.3 // indirect
16-
github.com/andybalholm/brotli v1.1.0 // indirect
13+
github.com/CycloneDX/cyclonedx-go v0.9.2 // indirect
14+
github.com/Microsoft/go-winio v0.6.2 // indirect
15+
github.com/ProtonMail/go-crypto v1.1.4 // indirect
16+
github.com/andybalholm/brotli v1.1.1 // indirect
1717
github.com/buger/jsonparser v1.1.1 // indirect
18-
github.com/c-bata/go-prompt v0.2.5 // indirect
18+
github.com/c-bata/go-prompt v0.2.6 // indirect
1919
github.com/chzyer/readline v1.5.1 // indirect
20-
github.com/cloudflare/circl v1.3.7 // indirect
21-
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
22-
github.com/cyphar/filepath-securejoin v0.2.5 // indirect
20+
github.com/cloudflare/circl v1.5.0 // indirect
21+
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
22+
github.com/cyphar/filepath-securejoin v0.3.6 // indirect
2323
github.com/dsnet/compress v0.0.1 // indirect
2424
github.com/emirpasic/gods v1.18.1 // indirect
2525
github.com/forPelevin/gomoji v1.2.0 // indirect
26-
github.com/fsnotify/fsnotify v1.7.0 // indirect
26+
github.com/fsnotify/fsnotify v1.8.0 // indirect
2727
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
28-
github.com/go-git/go-billy/v5 v5.6.0 // indirect
29-
github.com/go-git/go-git/v5 v5.13.0 // indirect
28+
github.com/go-git/go-billy/v5 v5.6.1 // indirect
29+
github.com/go-git/go-git/v5 v5.13.1 // indirect
3030
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
31-
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
31+
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
3232
github.com/golang/snappy v0.0.4 // indirect
3333
github.com/google/uuid v1.6.0 // indirect
3434
github.com/gookit/color v1.5.4 // indirect
3535
github.com/hashicorp/hcl v1.0.0 // indirect
3636
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
3737
github.com/jedib0t/go-pretty/v6 v6.6.5 // indirect
3838
github.com/jfrog/archiver/v3 v3.6.1 // indirect
39-
github.com/jfrog/build-info-go v1.10.7 // indirect
39+
github.com/jfrog/build-info-go v1.10.8 // indirect
4040
github.com/jfrog/gofrog v1.7.6 // indirect
4141
github.com/kevinburke/ssh_config v1.2.0 // indirect
42-
github.com/klauspost/compress v1.17.9 // indirect
43-
github.com/klauspost/cpuid/v2 v2.2.3 // indirect
42+
github.com/klauspost/compress v1.17.11 // indirect
43+
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
4444
github.com/klauspost/pgzip v1.2.6 // indirect
4545
github.com/magiconair/properties v1.8.9 // indirect
4646
github.com/manifoldco/promptui v0.9.0 // indirect
4747
github.com/mattn/go-colorable v0.1.13 // indirect
48-
github.com/mattn/go-isatty v0.0.17 // indirect
48+
github.com/mattn/go-isatty v0.0.20 // indirect
4949
github.com/mattn/go-runewidth v0.0.16 // indirect
50-
github.com/mattn/go-tty v0.0.3 // indirect
50+
github.com/mattn/go-tty v0.0.7 // indirect
5151
github.com/minio/sha256-simd v1.0.1 // indirect
5252
github.com/mitchellh/mapstructure v1.5.0 // indirect
53+
github.com/mmcloughlin/avo v0.6.0 // indirect
5354
github.com/nwaples/rardecode v1.1.3 // indirect
54-
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
55-
github.com/pierrec/lz4/v4 v4.1.21 // indirect
56-
github.com/pjbgf/sha1cd v0.3.0 // indirect
55+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
56+
github.com/pierrec/lz4/v4 v4.1.22 // indirect
57+
github.com/pjbgf/sha1cd v0.3.1 // indirect
5758
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
58-
github.com/pkg/term v1.1.0 // indirect
59+
github.com/pkg/term v1.2.0-beta.2 // indirect
5960
github.com/rivo/uniseg v0.4.7 // indirect
6061
github.com/russross/blackfriday/v2 v2.1.0 // indirect
61-
github.com/sagikazarmark/locafero v0.4.0 // indirect
62+
github.com/sagikazarmark/locafero v0.6.0 // indirect
6263
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
6364
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
6465
github.com/skeema/knownhosts v1.3.0 // indirect
6566
github.com/sourcegraph/conc v0.3.0 // indirect
6667
github.com/spf13/afero v1.11.0 // indirect
67-
github.com/spf13/cast v1.6.0 // indirect
68+
github.com/spf13/cast v1.7.1 // indirect
6869
github.com/spf13/pflag v1.0.5 // indirect
6970
github.com/spf13/viper v1.19.0 // indirect
7071
github.com/subosito/gotenv v1.6.0 // indirect
7172
github.com/ulikunitz/xz v0.5.12 // indirect
7273
github.com/urfave/cli v1.22.16 // indirect
7374
github.com/xanzy/ssh-agent v0.3.3 // indirect
7475
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
75-
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
76-
go.uber.org/atomic v1.9.0 // indirect
77-
go.uber.org/multierr v1.9.0 // indirect
78-
golang.org/x/crypto v0.31.0 // indirect
79-
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
76+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
77+
go.uber.org/multierr v1.11.0 // indirect
78+
golang.org/x/crypto v0.32.0 // indirect
79+
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
8080
golang.org/x/mod v0.22.0 // indirect
81-
golang.org/x/net v0.33.0 // indirect
81+
golang.org/x/net v0.34.0 // indirect
8282
golang.org/x/sync v0.10.0 // indirect
83-
golang.org/x/sys v0.28.0 // indirect
84-
golang.org/x/term v0.27.0 // indirect
83+
golang.org/x/sys v0.29.0 // indirect
84+
golang.org/x/term v0.28.0 // indirect
8585
golang.org/x/text v0.21.0 // indirect
86-
golang.org/x/tools v0.27.0 // indirect
86+
golang.org/x/tools v0.29.0 // indirect
8787
gopkg.in/ini.v1 v1.67.0 // indirect
8888
gopkg.in/warnings.v0 v0.1.2 // indirect
8989
gopkg.in/yaml.v3 v3.0.1 // indirect

0 commit comments

Comments
 (0)