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
15 changes: 15 additions & 0 deletions application/app/auth/app_details.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package auth

import "github.com/jfrog/jfrog-client-go/auth"

type appDetails struct {
auth.CommonConfigFields
}

func NewAppDetails() auth.ServiceDetails {
return &appDetails{}
}

func (rt *appDetails) GetVersion() (string, error) {
panic("Failed: Method is not implemented")
}
35 changes: 35 additions & 0 deletions application/app/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package app

import (
"github.com/jfrog/jfrog-cli-application/application/service"
)

type Context interface {
GetVersionService() service.VersionService
GetSystemService() service.SystemService
GetConfig() interface{}
}

type context struct {
versionService service.VersionService
systemService service.SystemService
}

func NewAppContext() Context {
return &context{
versionService: service.NewVersionService(),
systemService: service.NewSystemService(),
}
}

func (c *context) GetVersionService() service.VersionService {
return c.versionService
}

func (c *context) GetSystemService() service.SystemService {
return c.systemService
}

func (c *context) GetConfig() interface{} {
return nil
}
40 changes: 31 additions & 9 deletions application/cli/cli.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
package cli

import (
"github.com/jfrog/jfrog-cli-application/application/app"
"github.com/jfrog/jfrog-cli-application/application/commands/system"
"github.com/jfrog/jfrog-cli-application/application/commands/version"
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
)

const category = "Application Lifecycle"

Check failure on line 10 in application/cli/cli.go

View workflow job for this annotation

GitHub Actions / Static-Check

const `category` is unused (unused)

Check failure on line 10 in application/cli/cli.go

View workflow job for this annotation

GitHub Actions / Static-Check

const `category` is unused (unused)

//
//func GetJfrogApplicationCli() components.App {
// appContext := app.NewAppContext()
// appEntity := components.CreateEmbeddedApp(
// category,
// nil,
// components.Namespace{
// Name: "app",
// Description: "Tools for Application Lifecycle management",
// Category: category,
// Commands: []components.Command{
// system.GetPingCommand(appContext),
// version.GetCreateAppVersionCommand(appContext),
// },
// },
// )
// return appEntity
//}

func GetJfrogApplicationCli() components.App {
app := components.CreateEmbeddedApp(
category,
nil,
components.Namespace{
Name: "app",
Description: "Tools for Application Lifecycle management",
Category: category,
Commands: []components.Command{},
appContext := app.NewAppContext()
appEntity := components.CreateApp(
"app",
"1.0.0",
"JFrog Application CLI",
[]components.Command{
system.GetPingCommand(appContext),
version.GetCreateAppVersionCommand(appContext),
},
)
return app
return appEntity
}
71 changes: 71 additions & 0 deletions application/commands/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package commands

import pluginsCommon "github.com/jfrog/jfrog-cli-core/v2/plugins/common"

Check failure on line 3 in application/commands/flags.go

View workflow job for this annotation

GitHub Actions / Static-Check

File is not properly formatted (gofumpt)

Check failure on line 3 in application/commands/flags.go

View workflow job for this annotation

GitHub Actions / Static-Check

File is not properly formatted (gofumpt)
import "github.com/jfrog/jfrog-cli-core/v2/plugins/components"

const (
Ping = "ping"
CreateAppVersion = "create-app-version"
)

const (
ServerId = "server-id"
url = "url"
user = "user"
accessToken = "access-token"
ProjectFlag = "project"

ApplicationKeyFlag = "app-key"
PackageTypeFlag = "package-type"
PackageNameFlag = "package-name"
PackageVersionFlag = "package-version"
PackageRepositoryFlag = "package-repository"
SpecFlag = "spec"
SpecVarsFlag = "spec-vars"
)

// Flag keys mapped to their corresponding components.Flag definition.
var flagsMap = map[string]components.Flag{
// Common commands flags
ServerId: components.NewStringFlag(ServerId, "Server ID configured using the config command.", func(f *components.StringFlag) { f.Mandatory = false }),
url: components.NewStringFlag(url, "JFrog Platform URL.", func(f *components.StringFlag) { f.Mandatory = false }),
user: components.NewStringFlag(user, "JFrog username.", func(f *components.StringFlag) { f.Mandatory = false }),
accessToken: components.NewStringFlag(accessToken, "JFrog access token.", func(f *components.StringFlag) { f.Mandatory = false }),
ProjectFlag: components.NewStringFlag(ProjectFlag, "Project key associated with the created evidence.", func(f *components.StringFlag) { f.Mandatory = false }),

ApplicationKeyFlag: components.NewStringFlag(ApplicationKeyFlag, "Application key.", func(f *components.StringFlag) { f.Mandatory = true }),
PackageTypeFlag: components.NewStringFlag(PackageTypeFlag, "Package type.", func(f *components.StringFlag) { f.Mandatory = false }),
PackageNameFlag: components.NewStringFlag(PackageNameFlag, "Package name.", func(f *components.StringFlag) { f.Mandatory = false }),
PackageVersionFlag: components.NewStringFlag(PackageVersionFlag, "Package version.", func(f *components.StringFlag) { f.Mandatory = false }),
PackageRepositoryFlag: components.NewStringFlag(PackageRepositoryFlag, "Package storing repository.", func(f *components.StringFlag) { f.Mandatory = false }),
SpecFlag: components.NewStringFlag(SpecFlag, "A path to the specification file.", func(f *components.StringFlag) { f.Mandatory = false }),
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 }),
}

var commandFlags = map[string][]string{
CreateAppVersion: {
url,
user,
accessToken,
ServerId,
ProjectFlag,
ApplicationKeyFlag,
PackageTypeFlag,
PackageNameFlag,
PackageVersionFlag,
PackageRepositoryFlag,
SpecFlag,
SpecVarsFlag,
},

Ping: {
url,
user,
accessToken,
ServerId,
},
}

func GetCommandFlags(cmdKey string) []components.Flag {
return pluginsCommon.GetCommandFlags(cmdKey, commandFlags, flagsMap)
}
52 changes: 52 additions & 0 deletions application/commands/system/ping_cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package system

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

type pingCommand struct {
systemService service.SystemService
serverDetails *coreConfig.ServerDetails
}

func (pc *pingCommand) Run() error {
ctx := &service.Context{ServerDetails: pc.serverDetails}
return pc.systemService.Ping(ctx)
}

func (pc *pingCommand) ServerDetails() (*coreConfig.ServerDetails, error) {
return pc.serverDetails, nil
}

func (pc *pingCommand) CommandName() string {
return commands.Ping
}

func (pc *pingCommand) prepareAndRunCommand(ctx *components.Context) error {
serverDetails, err := utils.ServerDetailsByFlags(ctx)
if err != nil {
return err
}
pc.serverDetails = serverDetails
return commonCLiCommands.Exec(pc)
}

func GetPingCommand(appContext app.Context) components.Command {
cmd := &pingCommand{systemService: appContext.GetSystemService()}
return components.Command{
Name: commands.Ping,
Description: "Ping the application server",
Category: common.CategorySystem,
Aliases: []string{"p"},
Arguments: []components.Argument{},
Flags: commands.GetCommandFlags(commands.Ping),
Action: cmd.prepareAndRunCommand,
}
}
39 changes: 39 additions & 0 deletions application/commands/utils/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package utils

import (
"fmt"

Check failure on line 4 in application/commands/utils/utils.go

View workflow job for this annotation

GitHub Actions / Static-Check

File is not properly formatted (gofumpt)

Check failure on line 4 in application/commands/utils/utils.go

View workflow job for this annotation

GitHub Actions / Static-Check

File is not properly formatted (gofumpt)
commonCliUtils "github.com/jfrog/jfrog-cli-core/v2/common/cliutils"
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"
"github.com/jfrog/jfrog-client-go/utils"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
)

func AssertValueProvided(c *components.Context, fieldName string) error {
if c.GetStringFlagValue(fieldName) == "" {
return errorutils.CheckErrorf("the --%s option is mandatory", fieldName)
}
return nil
}

func PlatformToApplicationUrls(details *coreConfig.ServerDetails) {
details.ArtifactoryUrl = utils.AddTrailingSlashIfNeeded(details.Url) + "artifactory/"
details.EvidenceUrl = utils.AddTrailingSlashIfNeeded(details.Url) + "evidence/"
details.MetadataUrl = utils.AddTrailingSlashIfNeeded(details.Url) + "metadata/"
}

func ServerDetailsByFlags(ctx *components.Context) (*coreConfig.ServerDetails, error) {
serverDetails, err := pluginsCommon.CreateServerDetailsWithConfigOffer(ctx, true, commonCliUtils.Platform)
if err != nil {
return nil, err
}
if serverDetails.Url == "" {
return nil, fmt.Errorf("platform URL is mandatory for evidence commands")
}
if serverDetails.GetUser() != "" && serverDetails.GetPassword() != "" {
return nil, fmt.Errorf("evidence service does not support basic authentication")
}

return serverDetails, nil
}
Loading
Loading