Skip to content

Commit e0f705d

Browse files
committed
Added create version command
1 parent e347a2c commit e0f705d

File tree

9 files changed

+158
-16
lines changed

9 files changed

+158
-16
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package auth
2+
3+
import "github.com/jfrog/jfrog-client-go/auth"
4+
5+
type appDetails struct {
6+
auth.CommonConfigFields
7+
}
8+
9+
func NewAppDetails() auth.ServiceDetails {
10+
return &appDetails{}
11+
}
12+
13+
func (rt *appDetails) GetVersion() (string, error) {
14+
panic("Failed: Method is not implemented")
15+
}

application/app/context.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package app
2+
3+
import (
4+
"github.com/jfrog/jfrog-cli-application/application/service"
5+
)
6+
7+
type Context interface {
8+
GetVersionService() service.VersionService
9+
GetSystemService() service.SystemService
10+
GetConfig() interface{}
11+
}
12+
13+
type context struct {
14+
versionService service.VersionService
15+
systemService service.SystemService
16+
}
17+
18+
func NewAppContext() Context {
19+
return &context{
20+
versionService: service.NewVersionService(),
21+
systemService: service.NewSystemService(),
22+
}
23+
}
24+
25+
func (c *context) GetVersionService() service.VersionService {
26+
return c.versionService
27+
}
28+
29+
func (c *context) GetSystemService() service.SystemService {
30+
return c.systemService
31+
}
32+
33+
func (c *context) GetConfig() interface{} {
34+
return nil
35+
}

application/cli/cli.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
app2 "github.com/jfrog/jfrog-cli-application/application/app"
45
"github.com/jfrog/jfrog-cli-application/application/commands/system"
56
"github.com/jfrog/jfrog-cli-application/application/commands/version"
67
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
@@ -9,6 +10,7 @@ import (
910
const category = "Application Lifecycle"
1011

1112
func GetJfrogApplicationCli() components.App {
13+
appContext := app2.NewAppContext()
1214
app := components.CreateEmbeddedApp(
1315
category,
1416
nil,
@@ -17,8 +19,8 @@ func GetJfrogApplicationCli() components.App {
1719
Description: "Tools for Application Lifecycle management",
1820
Category: category,
1921
Commands: []components.Command{
20-
system.GetPingCommand(),
21-
version.GetCreateVersionCommand(),
22+
system.GetPingCommand(appContext),
23+
version.GetCreateVersionCommand(appContext),
2224
},
2325
},
2426
)
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
package system
22

33
import (
4+
"github.com/jfrog/jfrog-cli-application/application/app"
45
"github.com/jfrog/jfrog-cli-application/application/common"
6+
"github.com/jfrog/jfrog-cli-application/application/service"
57
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
68
)
79

810
type pingCommand struct {
9-
ctx *components.Context
11+
systemService service.SystemService
1012
}
1113

12-
func (pc *pingCommand) executeCmd(ctx *components.Context) error {
13-
return ctx.PrintCommandHelp(ctx.CommandName)
14+
func (pc *pingCommand) executeCmd(commandCtx *components.Context) error {
15+
ping, err := pc.systemService.Ping()
16+
if err != nil {
17+
return err
18+
}
19+
20+
println(ping)
21+
return nil
1422
}
1523

16-
func GetPingCommand() components.Command {
24+
func GetPingCommand(appContext app.Context) components.Command {
25+
cmd := &pingCommand{systemService: appContext.GetSystemService()}
1726
return components.Command{
1827
Name: "ping",
1928
Description: "Ping the application server",
@@ -22,9 +31,8 @@ func GetPingCommand() components.Command {
2231
Arguments: []components.Argument{},
2332
Flags: []components.Flag{},
2433
EnvVars: []components.EnvVar{},
25-
Action: func(c *components.Context) error {
26-
cmd := &pingCommand{ctx: c}
27-
return cmd.executeCmd(c)
34+
Action: func(commandCtx *components.Context) error {
35+
return cmd.executeCmd(commandCtx)
2836
},
2937
}
3038
}
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package version
22

33
import (
4+
"github.com/jfrog/jfrog-cli-application/application/app"
45
"github.com/jfrog/jfrog-cli-application/application/common"
6+
"github.com/jfrog/jfrog-cli-application/application/model"
7+
"github.com/jfrog/jfrog-cli-application/application/service"
58
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
69
)
710

811
type createVersionCommand struct {
9-
ctx *components.Context
12+
versionService service.VersionService
1013
}
1114

12-
func (cv *createVersionCommand) executeCmd(ctx *components.Context) error {
13-
return ctx.PrintCommandHelp(ctx.CommandName)
15+
func (cv *createVersionCommand) executeCmd(commandCtx *components.Context) error {
16+
versionRequest := &model.CreateVersionRequest{}
17+
return cv.versionService.CreateVersion(versionRequest)
1418
}
1519

16-
func GetCreateVersionCommand() components.Command {
20+
func GetCreateVersionCommand(appContext app.Context) components.Command {
21+
cmd := &createVersionCommand{versionService: appContext.GetVersionService()}
1722
return components.Command{
1823
Name: "create-version",
1924
Description: "Create application version",
@@ -22,9 +27,8 @@ func GetCreateVersionCommand() components.Command {
2227
Arguments: []components.Argument{},
2328
Flags: []components.Flag{},
2429
EnvVars: []components.EnvVar{},
25-
Action: func(c *components.Context) error {
26-
cmd := &createVersionCommand{ctx: c}
27-
return cmd.executeCmd(c)
30+
Action: func(commandCtx *components.Context) error {
31+
return cmd.executeCmd(commandCtx)
2832
},
2933
}
3034
}

application/http/http_client.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package http
2+
3+
import "github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
4+
5+
type AppHttpClient struct {
6+
client *jfroghttpclient.JfrogHttpClient
7+
}
8+
9+
func NewAppHttpClient() (*AppHttpClient, error) {
10+
client, err := jfroghttpclient.JfrogClientBuilder().
11+
SetCertificatesPath("").
12+
Build()
13+
14+
if err != nil {
15+
return nil, err
16+
}
17+
18+
return &AppHttpClient{client: client}, nil
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package model
2+
3+
type CreateVersionRequest struct {
4+
ApplicationKey string `json:"application_key"`
5+
Version string `json:"version"`
6+
Packages []*CreateVersionPackage `json:"packages"`
7+
}
8+
9+
type CreateVersionPackage struct {
10+
Type string `json:"type"`
11+
Name string `json:"name"`
12+
Version string `json:"version"`
13+
Repository string `json:"repository"`
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package service
2+
3+
type SystemService interface {
4+
Ping() (string, error)
5+
}
6+
7+
type systemService struct {
8+
}
9+
10+
func NewSystemService() SystemService {
11+
return &systemService{}
12+
}
13+
14+
func (ss *systemService) Ping() (string, error) {
15+
return "pong", nil
16+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package service
2+
3+
import (
4+
"github.com/jfrog/jfrog-cli-application/application/model"
5+
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
6+
)
7+
8+
type VersionService interface {
9+
CreateVersion(request *model.CreateVersionRequest) error
10+
}
11+
12+
type versionService struct {
13+
}
14+
15+
func NewVersionService() VersionService {
16+
return &versionService{}
17+
}
18+
19+
func (vs *versionService) CreateVersion(request *model.CreateVersionRequest) error {
20+
client, err := jfroghttpclient.JfrogClientBuilder().
21+
SetCertificatesPath("").
22+
Build()
23+
if err != nil {
24+
return err
25+
}
26+
27+
client.SendPost()
28+
return nil
29+
}

0 commit comments

Comments
 (0)