Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apptrust/commands/application/create_app_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func GetCreateAppCommand(appContext app.Context) components.Command {
Name: "create",
Description: "Create a new application",
Category: common.CategoryApplication,
Aliases: []string{"c"},
Arguments: []components.Argument{
{
Name: "application-key",
Expand Down
1 change: 1 addition & 0 deletions apptrust/commands/application/delete_app_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func GetDeleteAppCommand(appContext app.Context) components.Command {
Name: "delete",
Description: "Delete an application",
Category: common.CategoryApplication,
Aliases: []string{"d"},
Arguments: []components.Argument{
{
Name: "application-key",
Expand Down
1 change: 1 addition & 0 deletions apptrust/commands/application/update_app_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func GetUpdateAppCommand(appContext app.Context) components.Command {
Name: "update",
Description: "Update an existing application",
Category: common.CategoryApplication,
Aliases: []string{"u"},
Arguments: []components.Argument{
{
Name: "application-key",
Expand Down
17 changes: 12 additions & 5 deletions apptrust/commands/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (

const (
Ping = "ping"
CreateAppVersion = "create-app-version"
PromoteAppVersion = "promote-app-version"
CreateApp = "create-app"
UpdateApp = "update-app"
DeleteApp = "delete-app"
CreateAppVersion = "version-create"
PromoteAppVersion = "version-promote"
DeleteAppVersion = "version-delete"
CreateApp = "app-create"
UpdateApp = "app-update"
DeleteApp = "app-delete"
)

const (
Expand Down Expand Up @@ -90,6 +91,12 @@ var commandFlags = map[string][]string{
ApplicationKeyFlag,
StageVarsFlag,
},
DeleteAppVersion: {
url,
user,
accessToken,
serverId,
},

Ping: {
url,
Expand Down
2 changes: 1 addition & 1 deletion apptrust/commands/version/create_app_version_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func GetCreateAppVersionCommand(appContext app.Context) components.Command {
Name: commands.CreateAppVersion,
Description: "Create application version",
Category: common.CategoryVersion,
Aliases: []string{"cav"},
Aliases: []string{"vc"},
Arguments: []components.Argument{
{
Name: "version-name",
Expand Down
79 changes: 79 additions & 0 deletions apptrust/commands/version/delete_app_version_cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package version

import (
"github.com/jfrog/jfrog-cli-application/apptrust/app"
"github.com/jfrog/jfrog-cli-application/apptrust/commands"
"github.com/jfrog/jfrog-cli-application/apptrust/commands/utils"
"github.com/jfrog/jfrog-cli-application/apptrust/common"
"github.com/jfrog/jfrog-cli-application/apptrust/service"
"github.com/jfrog/jfrog-cli-application/apptrust/service/versions"
commonCLiCommands "github.com/jfrog/jfrog-cli-core/v2/common/commands"
pluginsCommon "github.com/jfrog/jfrog-cli-core/v2/plugins/common"
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
)

type deleteAppVersionCommand struct {
versionService versions.VersionService
serverDetails *coreConfig.ServerDetails
applicationKey string
version string
}

func (dv *deleteAppVersionCommand) Run() error {
ctx, err := service.NewContext(*dv.serverDetails)
if err != nil {
return err
}

return dv.versionService.DeleteAppVersion(ctx, dv.applicationKey, dv.version)
}

func (dv *deleteAppVersionCommand) ServerDetails() (*coreConfig.ServerDetails, error) {
return dv.serverDetails, nil
}

func (dv *deleteAppVersionCommand) CommandName() string {
return commands.DeleteAppVersion
}

func (dv *deleteAppVersionCommand) prepareAndRunCommand(ctx *components.Context) error {
if len(ctx.Arguments) != 2 {
return pluginsCommon.WrongNumberOfArgumentsHandler(ctx)
}

dv.applicationKey = ctx.Arguments[0]
dv.version = ctx.Arguments[1]

var err error
dv.serverDetails, err = utils.ServerDetailsByFlags(ctx)
if err != nil {
return err
}

return commonCLiCommands.Exec(dv)
}

func GetDeleteAppVersionCommand(appContext app.Context) components.Command {
cmd := &deleteAppVersionCommand{versionService: appContext.GetVersionService()}
return components.Command{
Name: commands.DeleteAppVersion,
Description: "Delete application version",
Category: common.CategoryVersion,
Aliases: []string{"vd"},
Arguments: []components.Argument{
{
Name: "application-key",
Description: "The application key",
Optional: false,
},
{
Name: "version",
Description: "The name of the version to delete",
Optional: false,
},
},
Flags: commands.GetCommandFlags(commands.DeleteAppVersion),
Action: cmd.prepareAndRunCommand,
}
}
58 changes: 58 additions & 0 deletions apptrust/commands/version/delete_app_version_cmd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package version

import (
"errors"
"testing"

mockversions "github.com/jfrog/jfrog-cli-application/apptrust/service/versions/mocks"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)

func TestDeleteAppVersionCommand_Run(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

serverDetails := &config.ServerDetails{Url: "https://example.com"}
applicationKey := "app-key"
version := "1.0.0"

mockVersionService := mockversions.NewMockVersionService(ctrl)
mockVersionService.EXPECT().DeleteAppVersion(gomock.Any(), applicationKey, version).
Return(nil).Times(1)

cmd := &deleteAppVersionCommand{
versionService: mockVersionService,
serverDetails: serverDetails,
applicationKey: applicationKey,
version: version,
}

err := cmd.Run()
assert.NoError(t, err)
}

func TestDeleteAppVersionCommand_Run_Error(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

serverDetails := &config.ServerDetails{Url: "https://example.com"}
applicationKey := "app-key"
version := "1.0.0"

mockVersionService := mockversions.NewMockVersionService(ctrl)
mockVersionService.EXPECT().DeleteAppVersion(gomock.Any(), applicationKey, version).
Return(errors.New("delete error")).Times(1)

cmd := &deleteAppVersionCommand{
versionService: mockVersionService,
serverDetails: serverDetails,
applicationKey: applicationKey,
version: version,
}

err := cmd.Run()
assert.Error(t, err)
assert.Equal(t, "delete error", err.Error())
}
2 changes: 1 addition & 1 deletion apptrust/commands/version/promote_app_version_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func GetPromoteAppVersionCommand(appContext app.Context) components.Command {
Name: commands.PromoteAppVersion,
Description: "Promote application version",
Category: common.CategoryVersion,
Aliases: []string{"pav"},
Aliases: []string{"vp"},
Arguments: []components.Argument{
{
Name: "version-name",
Expand Down
20 changes: 18 additions & 2 deletions apptrust/service/versions/version_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type VersionService interface {
CreateAppVersion(ctx service.Context, request *model.CreateAppVersionRequest) error
PromoteAppVersion(ctx service.Context, payload *model.PromoteAppVersionRequest) error
DeleteAppVersion(ctx service.Context, applicationKey string, version string) error
}

type versionService struct{}
Expand All @@ -22,7 +23,7 @@ func NewVersionService() VersionService {
}

func (vs *versionService) CreateAppVersion(ctx service.Context, request *model.CreateAppVersionRequest) error {
response, responseBody, err := ctx.GetHttpClient().Post("/v1/version", request)
response, responseBody, err := ctx.GetHttpClient().Post("/v1/applications/version", request)
if err != nil {
return err
}
Expand All @@ -36,7 +37,7 @@ func (vs *versionService) CreateAppVersion(ctx service.Context, request *model.C
}

func (vs *versionService) PromoteAppVersion(ctx service.Context, payload *model.PromoteAppVersionRequest) error {
response, responseBody, err := ctx.GetHttpClient().Post("/v1/version/promote", payload)
response, responseBody, err := ctx.GetHttpClient().Post("/v1/applications/version/promote", payload)
if err != nil {
return err
}
Expand All @@ -48,3 +49,18 @@ func (vs *versionService) PromoteAppVersion(ctx service.Context, payload *model.

return nil
}

func (vs *versionService) DeleteAppVersion(ctx service.Context, applicationKey string, version string) error {
url := fmt.Sprintf("/v1/applications/%s/versions/%s", applicationKey, version)
response, responseBody, err := ctx.GetHttpClient().Delete(url)
if err != nil {
return err
}

if response.StatusCode != 204 {
return fmt.Errorf("failed to delete app version. Status code: %d.\n%s",
response.StatusCode, responseBody)
}

return nil
}
4 changes: 2 additions & 2 deletions apptrust/service/versions/version_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestCreateAppVersion(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mockHttpClient := mockhttp.NewMockApptrustHttpClient(ctrl)
mockHttpClient.EXPECT().Post("/v1/version", tt.request).
mockHttpClient.EXPECT().Post("/v1/applications/version", tt.request).
Return(tt.mockResponse, []byte(tt.mockResponseBody), tt.mockError).Times(1)

mockCtx := mockservice.NewMockContext(ctrl)
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestPromoteAppVersion(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mockHttpClient := mockhttp.NewMockApptrustHttpClient(ctrl)
mockHttpClient.EXPECT().Post("/v1/version/promote", tt.payload).
mockHttpClient.EXPECT().Post("/v1/applications/version/promote", tt.payload).
Return(tt.mockResponse, []byte(tt.mockResponseBody), tt.mockError).Times(1)

mockCtx := mockservice.NewMockContext(ctrl)
Expand Down
1 change: 1 addition & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func GetJfrogCliApptrustApp() components.App {
system.GetPingCommand(appContext),
version.GetCreateAppVersionCommand(appContext),
version.GetPromoteAppVersionCommand(appContext),
version.GetDeleteAppVersionCommand(appContext),
application.GetCreateAppCommand(appContext),
application.GetUpdateAppCommand(appContext),
application.GetDeleteAppCommand(appContext),
Expand Down
52 changes: 26 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
module github.com/jfrog/jfrog-cli-application

go 1.23.4
go 1.23.7

toolchain go1.23.9

require (
github.com/jfrog/jfrog-cli-core/v2 v2.57.6
github.com/jfrog/jfrog-client-go v1.49.0
github.com/jfrog/jfrog-cli-core/v2 v2.58.7
github.com/jfrog/jfrog-client-go v1.53.1
github.com/stretchr/testify v1.10.0
go.uber.org/mock v0.5.0
github.com/urfave/cli v1.22.16
go.uber.org/mock v0.5.2
)

require (
dario.cat/mergo v1.0.1 // indirect
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/CycloneDX/cyclonedx-go v0.9.2 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.1.4 // indirect
github.com/ProtonMail/go-crypto v1.1.6 // indirect
github.com/andybalholm/brotli v1.1.1 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/c-bata/go-prompt v0.2.6 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cloudflare/circl v1.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
github.com/cyphar/filepath-securejoin v0.4.0 // indirect
github.com/cloudflare/circl v1.6.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dsnet/compress v0.0.1 // indirect
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/forPelevin/gomoji v1.2.0 // indirect
github.com/forPelevin/gomoji v1.3.0 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.6.2 // indirect
github.com/go-git/go-git/v5 v5.13.1 // indirect
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
github.com/go-git/go-git/v5 v5.14.0 // indirect
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 // indirect
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
Expand All @@ -39,7 +43,7 @@ require (
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jedib0t/go-pretty/v6 v6.6.5 // indirect
github.com/jfrog/archiver/v3 v3.6.1 // indirect
github.com/jfrog/build-info-go v1.10.8 // indirect
github.com/jfrog/build-info-go v1.10.12 // indirect
github.com/jfrog/gofrog v1.7.6 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.17.11 // indirect
Expand All @@ -53,11 +57,10 @@ require (
github.com/mattn/go-tty v0.0.7 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mmcloughlin/avo v0.6.0 // indirect
github.com/nwaples/rardecode v1.1.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pierrec/lz4/v4 v4.1.22 // indirect
github.com/pjbgf/sha1cd v0.3.1 // indirect
github.com/pjbgf/sha1cd v0.3.2 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pkg/term v1.2.0-beta.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand All @@ -66,28 +69,25 @@ require (
github.com/sagikazarmark/locafero v0.7.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.3.0 // indirect
github.com/skeema/knownhosts v1.3.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.12.0 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
github.com/urfave/cli v1.22.16 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/term v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.29.0 // indirect
golang.org/x/crypto v0.36.0 // indirect
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect
golang.org/x/net v0.38.0 // indirect
golang.org/x/sync v0.12.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/term v0.30.0 // indirect
golang.org/x/text v0.23.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading