Skip to content

Commit f96af20

Browse files
committed
Added create version command
1 parent 5616e2b commit f96af20

File tree

13 files changed

+624
-9
lines changed

13 files changed

+624
-9
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: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
11
package cli
22

33
import (
4+
"github.com/jfrog/jfrog-cli-application/application/app"
5+
"github.com/jfrog/jfrog-cli-application/application/commands/system"
6+
"github.com/jfrog/jfrog-cli-application/application/commands/version"
47
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
58
)
69

710
const category = "Application Lifecycle"
811

12+
//
13+
//func GetJfrogApplicationCli() components.App {
14+
// appContext := app.NewAppContext()
15+
// appEntity := components.CreateEmbeddedApp(
16+
// category,
17+
// nil,
18+
// components.Namespace{
19+
// Name: "app",
20+
// Description: "Tools for Application Lifecycle management",
21+
// Category: category,
22+
// Commands: []components.Command{
23+
// system.GetPingCommand(appContext),
24+
// version.GetCreateAppVersionCommand(appContext),
25+
// },
26+
// },
27+
// )
28+
// return appEntity
29+
//}
30+
931
func GetJfrogApplicationCli() components.App {
10-
app := components.CreateEmbeddedApp(
11-
category,
12-
nil,
13-
components.Namespace{
14-
Name: "app",
15-
Description: "Tools for Application Lifecycle management",
16-
Category: category,
17-
Commands: []components.Command{},
32+
appContext := app.NewAppContext()
33+
appEntity := components.CreateApp(
34+
"app",
35+
"1.0.0",
36+
"JFrog Application CLI",
37+
[]components.Command{
38+
system.GetPingCommand(appContext),
39+
version.GetCreateAppVersionCommand(appContext),
1840
},
1941
)
20-
return app
42+
return appEntity
2143
}

application/commands/flags.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package commands
2+
3+
import pluginsCommon "github.com/jfrog/jfrog-cli-core/v2/plugins/common"
4+
import "github.com/jfrog/jfrog-cli-core/v2/plugins/components"
5+
6+
const (
7+
Ping = "ping"
8+
CreateAppVersion = "create-app-version"
9+
)
10+
11+
const (
12+
ServerId = "server-id"
13+
url = "url"
14+
user = "user"
15+
accessToken = "access-token"
16+
ProjectFlag = "project"
17+
18+
ApplicationKeyFlag = "app-key"
19+
PackageTypeFlag = "package-type"
20+
PackageNameFlag = "package-name"
21+
PackageVersionFlag = "package-version"
22+
PackageRepositoryFlag = "package-repository"
23+
SpecFlag = "spec"
24+
SpecVarsFlag = "spec-vars"
25+
)
26+
27+
// Flag keys mapped to their corresponding components.Flag definition.
28+
var flagsMap = map[string]components.Flag{
29+
// Common commands flags
30+
ServerId: components.NewStringFlag(ServerId, "Server ID configured using the config command.", func(f *components.StringFlag) { f.Mandatory = false }),
31+
url: components.NewStringFlag(url, "JFrog Platform URL.", func(f *components.StringFlag) { f.Mandatory = false }),
32+
user: components.NewStringFlag(user, "JFrog username.", func(f *components.StringFlag) { f.Mandatory = false }),
33+
accessToken: components.NewStringFlag(accessToken, "JFrog access token.", func(f *components.StringFlag) { f.Mandatory = false }),
34+
ProjectFlag: components.NewStringFlag(ProjectFlag, "Project key associated with the created evidence.", func(f *components.StringFlag) { f.Mandatory = false }),
35+
36+
ApplicationKeyFlag: components.NewStringFlag(ApplicationKeyFlag, "Application key.", func(f *components.StringFlag) { f.Mandatory = true }),
37+
PackageTypeFlag: components.NewStringFlag(PackageTypeFlag, "Package type.", func(f *components.StringFlag) { f.Mandatory = false }),
38+
PackageNameFlag: components.NewStringFlag(PackageNameFlag, "Package name.", func(f *components.StringFlag) { f.Mandatory = false }),
39+
PackageVersionFlag: components.NewStringFlag(PackageVersionFlag, "Package version.", func(f *components.StringFlag) { f.Mandatory = false }),
40+
PackageRepositoryFlag: components.NewStringFlag(PackageRepositoryFlag, "Package storing repository.", func(f *components.StringFlag) { f.Mandatory = false }),
41+
SpecFlag: components.NewStringFlag(SpecFlag, "A path to the specification file.", func(f *components.StringFlag) { f.Mandatory = false }),
42+
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 }),
43+
}
44+
45+
var commandFlags = map[string][]string{
46+
CreateAppVersion: {
47+
url,
48+
user,
49+
accessToken,
50+
ServerId,
51+
ProjectFlag,
52+
ApplicationKeyFlag,
53+
PackageTypeFlag,
54+
PackageNameFlag,
55+
PackageVersionFlag,
56+
PackageRepositoryFlag,
57+
SpecFlag,
58+
SpecVarsFlag,
59+
},
60+
61+
Ping: {
62+
url,
63+
user,
64+
accessToken,
65+
ServerId,
66+
},
67+
}
68+
69+
func GetCommandFlags(cmdKey string) []components.Flag {
70+
return pluginsCommon.GetCommandFlags(cmdKey, commandFlags, flagsMap)
71+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package system
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/service"
9+
commonCLiCommands "github.com/jfrog/jfrog-cli-core/v2/common/commands"
10+
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
11+
coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
12+
)
13+
14+
type pingCommand struct {
15+
systemService service.SystemService
16+
serverDetails *coreConfig.ServerDetails
17+
}
18+
19+
func (pc *pingCommand) Run() error {
20+
ctx := &service.Context{ServerDetails: pc.serverDetails}
21+
return pc.systemService.Ping(ctx)
22+
}
23+
24+
func (pc *pingCommand) ServerDetails() (*coreConfig.ServerDetails, error) {
25+
return pc.serverDetails, nil
26+
}
27+
28+
func (pc *pingCommand) CommandName() string {
29+
return commands.Ping
30+
}
31+
32+
func (pc *pingCommand) prepareAndRunCommand(ctx *components.Context) error {
33+
serverDetails, err := utils.ServerDetailsByFlags(ctx)
34+
if err != nil {
35+
return err
36+
}
37+
pc.serverDetails = serverDetails
38+
return commonCLiCommands.Exec(pc)
39+
}
40+
41+
func GetPingCommand(appContext app.Context) components.Command {
42+
cmd := &pingCommand{systemService: appContext.GetSystemService()}
43+
return components.Command{
44+
Name: commands.Ping,
45+
Description: "Ping the application server",
46+
Category: common.CategorySystem,
47+
Aliases: []string{"p"},
48+
Arguments: []components.Argument{},
49+
Flags: commands.GetCommandFlags(commands.Ping),
50+
Action: cmd.prepareAndRunCommand,
51+
}
52+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package utils
2+
3+
import (
4+
"fmt"
5+
commonCliUtils "github.com/jfrog/jfrog-cli-core/v2/common/cliutils"
6+
pluginsCommon "github.com/jfrog/jfrog-cli-core/v2/plugins/common"
7+
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
8+
coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
9+
"github.com/jfrog/jfrog-client-go/utils"
10+
"github.com/jfrog/jfrog-client-go/utils/errorutils"
11+
)
12+
13+
func AssertValueProvided(c *components.Context, fieldName string) error {
14+
if c.GetStringFlagValue(fieldName) == "" {
15+
return errorutils.CheckErrorf("the --%s option is mandatory", fieldName)
16+
}
17+
return nil
18+
}
19+
20+
func PlatformToApplicationUrls(details *coreConfig.ServerDetails) {
21+
details.ArtifactoryUrl = utils.AddTrailingSlashIfNeeded(details.Url) + "artifactory/"
22+
details.EvidenceUrl = utils.AddTrailingSlashIfNeeded(details.Url) + "evidence/"
23+
details.MetadataUrl = utils.AddTrailingSlashIfNeeded(details.Url) + "metadata/"
24+
}
25+
26+
func ServerDetailsByFlags(ctx *components.Context) (*coreConfig.ServerDetails, error) {
27+
serverDetails, err := pluginsCommon.CreateServerDetailsWithConfigOffer(ctx, true, commonCliUtils.Platform)
28+
if err != nil {
29+
return nil, err
30+
}
31+
if serverDetails.Url == "" {
32+
return nil, fmt.Errorf("platform URL is mandatory for evidence commands")
33+
}
34+
if serverDetails.GetUser() != "" && serverDetails.GetPassword() != "" {
35+
return nil, fmt.Errorf("evidence service does not support basic authentication")
36+
}
37+
38+
return serverDetails, nil
39+
}

0 commit comments

Comments
 (0)