Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalbe4 committed Nov 4, 2024
2 parents af607d1 + 3029fdc commit de5f0bd
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 33 deletions.
19 changes: 10 additions & 9 deletions artifactory/utils/commandsummary/buildinfosummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container"
"github.com/jfrog/jfrog-client-go/utils/log"
"net/url"
"path"
"strings"
)
Expand Down Expand Up @@ -249,16 +250,16 @@ func isSupportedModule(module *buildInfo.Module) bool {
}

func createDockerMultiArchTitle(module *buildInfo.Module) string {
parentImageName := strings.Split(module.Parent, ":")[0]
var sha256 string
for _, artifact := range module.Artifacts {
if artifact.Name == container.ManifestJsonFile {
sha256 = artifact.Sha256
break
}
}
if StaticMarkdownConfig.IsExtendedSummary() {
dockerModuleLink := fmt.Sprintf(artifactoryDockerPackagesUiFormat, strings.TrimSuffix(StaticMarkdownConfig.GetPlatformUrl(), "/"), "%2F%2F"+parentImageName, sha256)
parentImageName := strings.Split(module.Parent, ":")[0]
var sha256 string
for _, artifact := range module.Artifacts {
if artifact.Name == container.ManifestJsonFile {
sha256 = artifact.Sha256
break
}
}
dockerModuleLink := fmt.Sprintf(artifactoryDockerPackagesUiFormat, strings.TrimSuffix(StaticMarkdownConfig.GetPlatformUrl(), "/"), "%2F%2F"+url.PathEscape(parentImageName), sha256)
return fmt.Sprintf("%s <a href=%s>(🐸 View)</a>", module.Id, dockerModuleLink)
}
return module.Id
Expand Down
11 changes: 6 additions & 5 deletions artifactory/utils/commandsummary/markdownConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package commandsummary
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"strings"

"github.com/jfrog/jfrog-client-go/http/httpclient"
clientUtils "github.com/jfrog/jfrog-client-go/utils"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/io/httputils"
"net/http"
"net/url"
"strings"
)

// Static struct to hold the Markdown configuration values
Expand Down Expand Up @@ -62,7 +63,7 @@ func (mg *MarkdownConfig) SetScanResultsMapping(resultsMap map[string]ScanResult

// Initializes the command summary values that effect Markdown generation
func InitMarkdownGenerationValues(serverUrl string, platformMajorVersion int) (err error) {
entitled, err := checkExtendedSummaryEntitled(serverUrl)
entitled, err := CheckExtendedSummaryEntitled(serverUrl)
if err != nil {
return
}
Expand All @@ -72,7 +73,7 @@ func InitMarkdownGenerationValues(serverUrl string, platformMajorVersion int) (e
return
}

func checkExtendedSummaryEntitled(serverUrl string) (bool, error) {
func CheckExtendedSummaryEntitled(serverUrl string) (bool, error) {
// Parse and validate the URL
parsedUrl, err := url.Parse(serverUrl)
if err != nil || !parsedUrl.IsAbs() {
Expand Down
6 changes: 5 additions & 1 deletion artifactory/utils/container/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ func (builder *buildInfoBuilder) createMultiPlatformBuildInfo(fatManifest *FatMa
Properties: imageProperties,
Artifacts: []buildinfo.Artifact{getFatManifestArtifact(searchResultFatManifest)},
}}}
imageLongNameWithoutRepo, err := builder.image.GetImageLongNameWithoutRepoWithTag()
if err != nil {
return nil, err
}
// Create all image arch modules
for _, manifest := range fatManifest.Manifests {
image := candidateImages[manifest.Digest]
Expand All @@ -378,7 +382,7 @@ func (builder *buildInfoBuilder) createMultiPlatformBuildInfo(fatManifest *FatMa
Id: getModuleIdByManifest(manifest, baseModuleId),
Type: buildinfo.Docker,
Artifacts: artifacts,
Parent: baseModuleId,
Parent: imageLongNameWithoutRepo,
})
}
return buildInfo, setBuildProperties(builder.buildName, builder.buildNumber, builder.project, builder.imageLayers, builder.serviceManager)
Expand Down
15 changes: 15 additions & 0 deletions artifactory/utils/container/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ func (image *Image) GetImageShortNameWithTag() (string, error) {
return imageName, nil
}

// GetImageLongNameWithoutRepoWithTag removes the registry hostname and repository name, returning the organization and image name with the tag.
// e.g., "docker-local/myorg/hello-world:latest" -> "myorg/hello-world:latest"
// e.g., "docker-local/hello-world:latest" -> "hello-world:latest"
func (image *Image) GetImageLongNameWithoutRepoWithTag() (string, error) {
longName, err := image.GetImageLongNameWithTag()
if err != nil {
return "", err
}
parts := strings.Split(longName, "/")
if len(parts) > 1 {
return strings.Join(parts[1:], "/"), nil
}
return longName, nil
}

// Get image tag name of an image.
// e.g.: https://my-registry/docker-local/hello-world:latest. -> latest
func (image *Image) GetImageTag() (string, error) {
Expand Down
22 changes: 22 additions & 0 deletions artifactory/utils/container/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ func TestGetImageLongNameWithTag(t *testing.T) {
_, err := NewImage("domain").GetImageLongNameWithTag()
assert.Error(t, err)
}

func TestGetImageLongNameWithoutRepoWithTag(t *testing.T) {
var imageTags = []struct {
in string
expected string
}{
{"domain:8080/repo-name/hello-world:latest", "hello-world:latest"},
{"domain/repo-name/hello-world:latest", "hello-world:latest"},
{"domain/repo-name/org-name/hello-world:latest", "org-name/hello-world:latest"},
{"domain/repo-name/org-name/hello-world", "org-name/hello-world:latest"},
}

for _, v := range imageTags {
result, err := NewImage(v.in).GetImageLongNameWithoutRepoWithTag()
assert.NoError(t, err)
assert.Equal(t, v.expected, result)
}
// Validate failure upon missing image name
_, err := NewImage("domain").GetImageLongNameWithoutRepoWithTag()
assert.Error(t, err)
}

func TestGetImageShortNameWithTag(t *testing.T) {
var imageTags = []struct {
in string
Expand Down
2 changes: 2 additions & 0 deletions common/commands/configfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ func handleInteractiveConfigCreation(configFile *ConfigFile, confType project.Pr
return configFile.configGradle()
case project.Terraform:
return configFile.setDeployer(false)
case project.Cocoapods:
return configFile.setDeployerResolver()
}
return
}
Expand Down
2 changes: 2 additions & 0 deletions common/project/projectconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
Dotnet
Build
Terraform
Cocoapods
)

type ConfigType string
Expand All @@ -62,6 +63,7 @@ var ProjectTypes = []string{
"dotnet",
"build",
"terraform",
"cocoapods",
}

func (projectType ProjectType) String() string {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/jedib0t/go-pretty/v6 v6.5.9
github.com/jfrog/build-info-go v1.10.3
github.com/jfrog/gofrog v1.7.6
github.com/jfrog/jfrog-client-go v1.47.3
github.com/jfrog/jfrog-client-go v1.47.4
github.com/magiconair/properties v1.8.7
github.com/manifoldco/promptui v0.9.0
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
Expand Down Expand Up @@ -96,7 +96,7 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect
)

// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240918081224-1c584cc334c7
// replace github.com/jfrog/jfrog-client-go => github.com/eyalbe4/jfrog-client-go v1.28.1-0.20241103083749-45c13ff7fe16

// replace github.com/jfrog/build-info-go => github.com/galusben/build-info-go v0.0.0-20240930113238-ac3b31030284

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ github.com/jfrog/build-info-go v1.10.3 h1:9nqBdZD6xkuxiOvxg+idZ79QLFWQNuucvKkl8X
github.com/jfrog/build-info-go v1.10.3/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=
github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4=
github.com/jfrog/jfrog-client-go v1.47.3 h1:99/JSSgU0rvnM2zWYos2n+Gz1IYLCUoIorE4Xco+Dew=
github.com/jfrog/jfrog-client-go v1.47.3/go.mod h1:NepfaidmK/xiKsVC+0Ur9sANOqL6io8Y7pSaCau7J6o=
github.com/jfrog/jfrog-client-go v1.47.4 h1:4FAuDDvoDRy9LEFe1WwUO5prBXkgyhaWGEZ0vXYL/Z4=
github.com/jfrog/jfrog-client-go v1.47.4/go.mod h1:NepfaidmK/xiKsVC+0Ur9sANOqL6io8Y7pSaCau7J6o=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
Expand Down
14 changes: 8 additions & 6 deletions plugins/components/conversionlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/jfrog/gofrog/datastructures"
"github.com/jfrog/jfrog-cli-core/v2/docs/common"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -80,7 +79,7 @@ func convertCommand(cmd Command, namespaces ...string) (cli.Command, error) {
if err != nil {
return cli.Command{}, err
}
return cli.Command{
cliCmd := cli.Command{
Name: cmd.Name,
Flags: convertedFlags,
Aliases: cmd.Aliases,
Expand All @@ -93,9 +92,12 @@ func convertCommand(cmd Command, namespaces ...string) (cli.Command, error) {
BashComplete: common.CreateBashCompletionFunc(),
SkipFlagParsing: cmd.SkipFlagParsing,
Hidden: cmd.Hidden,
}
if cmd.Action != nil {
// Passing any other interface than 'cli.ActionFunc' will fail the command.
Action: getActionFunc(cmd),
}, nil
cliCmd.Action = getActionFunc(cmd)
}
return cliCmd, nil
}

func removeEmptyValues(slice []string) []string {
Expand All @@ -112,8 +114,8 @@ func removeEmptyValues(slice []string) []string {
func createCommandUsages(cmd Command, convertedStringFlags map[string]StringFlag, namespaces ...string) (usages []string, err error) {
// Handle manual usages provided.
if cmd.UsageOptions != nil {
for _, manualUsage := range cmd.UsageOptions.Usage {
usages = append(usages, fmt.Sprintf("%s %s", coreutils.GetCliExecutableName(), manualUsage))
if cmd.UsageOptions.Usage != nil {
usages = append(usages, cmd.UsageOptions.Usage...)
}
if cmd.UsageOptions.ReplaceAutoGeneratedUsage {
return
Expand Down
10 changes: 2 additions & 8 deletions plugins/components/conversionlayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"testing"

"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
)
Expand All @@ -20,11 +19,6 @@ func TestCreateCommandUsages(t *testing.T) {
strFlag := NewStringFlag("flag", "", SetMandatory())

override := []string{"usage override", "usage override 2", "usage override 3"}
expectedOverride := []string{
fmt.Sprintf("%s %s", coreutils.GetCliExecutableName(), "usage override"),
fmt.Sprintf("%s %s", coreutils.GetCliExecutableName(), "usage override 2"),
fmt.Sprintf("%s %s", coreutils.GetCliExecutableName(), "usage override 3"),
}

tests := []struct {
name string
Expand Down Expand Up @@ -93,7 +87,7 @@ func TestCreateCommandUsages(t *testing.T) {
UsageOptions: &UsageOptions{Usage: override},
},
stringFlags: map[string]StringFlag{optStrFlag.Name: optStrFlag},
expected: append(expectedOverride,
expected: append(override,
fmt.Sprintf("%s [command options] <%s> <%s>", expectedPrefix, "first argument", "second"),
fmt.Sprintf("%s [command options] --%s=<%s> <%s>", expectedPrefix, optStrFlag.Name, optStrFlag.HelpValue, "first argument"),
),
Expand All @@ -107,7 +101,7 @@ func TestCreateCommandUsages(t *testing.T) {
UsageOptions: &UsageOptions{Usage: override, ReplaceAutoGeneratedUsage: true},
},
stringFlags: map[string]StringFlag{optStrFlag.Name: optStrFlag, strFlag.Name: strFlag},
expected: expectedOverride,
expected: override, // override is not expected to be changed upon using UsageOptions
},
}

Expand Down

0 comments on commit de5f0bd

Please sign in to comment.