Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalbe4 committed Jan 23, 2024
2 parents 39b06f7 + a3e93ce commit 8129e67
Show file tree
Hide file tree
Showing 230 changed files with 1,974 additions and 166,135 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v3
Expand All @@ -29,15 +29,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x

# Temporarily set version 2.18.0 to workaround https://github.com/securego/gosec/issues/1046
- name: Run Gosec Security Scanner
uses: securego/gosec@v2.18.0
uses: securego/gosec@master
with:
args: -exclude G204,G301,G302,G304,G306 -tests -exclude-dir \.*test\.* ./...
2 changes: 1 addition & 1 deletion .github/workflows/embedded-jar-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
env:
GOPROXY: direct
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Download JARs
run: buildscripts/download-jars.sh
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
GRADLE_OPTS: -Dorg.gradle.daemon=false
JFROG_CLI_LOG_LEVEL: "DEBUG"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Python3
uses: actions/setup-python@v4
Expand All @@ -39,12 +39,12 @@ jobs:
nuget-version: 6.x

- name: Install dotnet
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.x'

- name: Go Cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
Expand Down
4 changes: 4 additions & 0 deletions artifactory/commands/npm/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ func (npc *NpmPublishCommand) SetXrayScan(xrayScan bool) *NpmPublishCommand {
return npc
}

func (npc *NpmPublishCommand) GetXrayScan() bool {
return npc.xrayScan
}

func (npc *NpmPublishCommand) SetScanOutputFormat(format format.OutputFormat) *NpmPublishCommand {
npc.scanOutputFormat = format
return npc
Expand Down
102 changes: 101 additions & 1 deletion artifactory/commands/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,12 @@ var localRepoHandlers = map[string]repoHandler{
Go: localGoHandler,
Yum: localYumHandler,
Conan: localConanHandler,
Conda: localCondaHandler,
Chef: localChefHandler,
Puppet: localPuppetHandler,
Alpine: localAlpineHandler,
Generic: localGenericHandler,
Swift: localSwiftHandler,
}

func localMavenHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
Expand Down Expand Up @@ -589,6 +591,35 @@ func localAlpineHandler(servicesManager artifactory.ArtifactoryServicesManager,
return err
}

func localCondaHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
params := services.NewCondaLocalRepositoryParams()
err := json.Unmarshal(jsonConfig, &params)
if errorutils.CheckError(err) != nil {
return err
}
if isUpdate {
err = servicesManager.UpdateLocalRepository().Conda(params)
} else {
err = servicesManager.CreateLocalRepository().Conda(params)
}
return err
}

func localSwiftHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
params := services.NewSwiftLocalRepositoryParams()
err := json.Unmarshal(jsonConfig, &params)
if errorutils.CheckError(err) != nil {
return err
}

if isUpdate {
err = servicesManager.UpdateLocalRepository().Swift(params)
} else {
err = servicesManager.CreateLocalRepository().Swift(params)
}
return err
}

func localGenericHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
params := services.NewGenericLocalRepositoryParams()
err := json.Unmarshal(jsonConfig, &params)
Expand Down Expand Up @@ -626,13 +657,14 @@ var remoteRepoHandlers = map[string]repoHandler{
Go: remoteGoHandler,
Yum: remoteYumHandler,
Conan: remoteConanHandler,
Conda: remoteCondaHandler,
Chef: remoteChefHandler,
Puppet: remotePuppetHandler,
Conda: remoteCondaHandler,
P2: remoteP2Handler,
Vcs: remoteVcsHandler,
Alpine: remoteAlpineHandler,
Generic: remoteGenericHandler,
Swift: remoteSwiftHandler,
}

func remoteMavenHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
Expand Down Expand Up @@ -1013,6 +1045,20 @@ func remoteYumHandler(servicesManager artifactory.ArtifactoryServicesManager, js
return err
}

func remoteSwiftHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
params := services.NewSwiftRemoteRepositoryParams()
err := json.Unmarshal(jsonConfig, &params)
if errorutils.CheckError(err) != nil {
return err
}
if isUpdate {
err = servicesManager.UpdateRemoteRepository().Swift(params)
} else {
err = servicesManager.CreateRemoteRepository().Swift(params)
}
return err
}

func remoteGenericHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
params := services.NewGenericRemoteRepositoryParams()
err := json.Unmarshal(jsonConfig, &params)
Expand Down Expand Up @@ -1049,10 +1095,13 @@ var federatedRepoHandlers = map[string]repoHandler{
Gitlfs: federatedGitLfsHandler,
Go: federatedGoHandler,
Conan: federatedConanHandler,
Conda: federatedCondaHandler,
Chef: federatedChefHandler,
Puppet: federatedPuppetHandler,
Alpine: federatedAlpineHandler,
Generic: federatedGenericHandler,
Yum: federatedYumHandler,
Swift: federatedSwiftHandler,
}

func federatedMavenHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
Expand Down Expand Up @@ -1308,6 +1357,18 @@ func federatedConanHandler(servicesManager artifactory.ArtifactoryServicesManage
return servicesManager.CreateFederatedRepository().Conan(params)
}

func federatedCondaHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
params := services.NewCondaFederatedRepositoryParams()
err := json.Unmarshal(jsonConfig, &params)
if errorutils.CheckError(err) != nil {
return err
}
if isUpdate {
return servicesManager.UpdateFederatedRepository().Conda(params)
}
return servicesManager.CreateFederatedRepository().Conda(params)
}

func federatedChefHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
params := services.NewChefFederatedRepositoryParams()
err := json.Unmarshal(jsonConfig, &params)
Expand Down Expand Up @@ -1357,6 +1418,30 @@ func federatedGenericHandler(servicesManager artifactory.ArtifactoryServicesMana
return servicesManager.CreateFederatedRepository().Generic(params)
}

func federatedSwiftHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
params := services.NewSwiftFederatedRepositoryParams()
err := json.Unmarshal(jsonConfig, &params)
if errorutils.CheckError(err) != nil {
return err
}
if isUpdate {
return servicesManager.UpdateFederatedRepository().Swift(params)
}
return servicesManager.CreateFederatedRepository().Swift(params)
}

func federatedYumHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
params := services.NewYumFederatedRepositoryParams()
err := json.Unmarshal(jsonConfig, &params)
if errorutils.CheckError(err) != nil {
return err
}
if isUpdate {
return servicesManager.UpdateFederatedRepository().Yum(params)
}
return servicesManager.CreateFederatedRepository().Yum(params)
}

var virtualRepoHandlers = map[string]repoHandler{
Maven: virtualMavenHandler,
Gradle: virtualGradleHandler,
Expand All @@ -1382,6 +1467,7 @@ var virtualRepoHandlers = map[string]repoHandler{
P2: virtualP2Handler,
Alpine: virtualAlpineHandler,
Generic: virtualGenericHandler,
Swift: virtualSwiftHandler,
}

func virtualMavenHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
Expand Down Expand Up @@ -1706,6 +1792,20 @@ func virtualCondaHandler(servicesManager artifactory.ArtifactoryServicesManager,
return err
}

func virtualSwiftHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
params := services.NewSwiftVirtualRepositoryParams()
err := json.Unmarshal(jsonConfig, &params)
if errorutils.CheckError(err) != nil {
return err
}
if isUpdate {
err = servicesManager.UpdateVirtualRepository().Swift(params)
} else {
err = servicesManager.CreateVirtualRepository().Swift(params)
}
return err
}

func virtualGenericHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
params := services.NewGenericVirtualRepositoryParams()
err := json.Unmarshal(jsonConfig, &params)
Expand Down
1 change: 1 addition & 0 deletions artifactory/commands/repository/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const (
Alpine = "alpine"
Conda = "conda"
P2 = "p2"
Swift = "swift"

// Repo layout Refs
BowerDefaultRepoLayout = "bower-default"
Expand Down
7 changes: 1 addition & 6 deletions artifactory/commands/utils/conditionaluploadutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package utils

import (
"github.com/jfrog/jfrog-cli-core/v2/common/format"
xraycommands "github.com/jfrog/jfrog-cli-core/v2/xray/commands/scan"
"strings"

"github.com/jfrog/jfrog-cli-core/v2/common/spec"
Expand All @@ -13,7 +12,7 @@ import (
type ConditionalUploadScanFuncType func(serverDetails *config.ServerDetails, fileSpec *spec.SpecFiles, threads int, scanOutputFormat format.OutputFormat) error

// Function to run as a condition to upload. If not overridden, the default scan function is used.
var ConditionalUploadScanFunc ConditionalUploadScanFuncType = conditionalUploadDefaultScanFunc
var ConditionalUploadScanFunc ConditionalUploadScanFuncType = nil

// ScanDeployableArtifacts scans all files founds in the given parsed deployableArtifacts results.
// If the scan passes, the function returns two file-specs ready for upload. The first one contains all the binaries
Expand Down Expand Up @@ -49,7 +48,3 @@ func parseTargetPath(target, serverUrl string) string {
}
return target
}

func conditionalUploadDefaultScanFunc(serverDetails *config.ServerDetails, fileSpec *spec.SpecFiles, threads int, scanOutputFormat format.OutputFormat) error {
return xraycommands.NewScanCommand().SetServerDetails(serverDetails).SetSpec(fileSpec).SetThreads(threads).SetOutputFormat(scanOutputFormat).SetFail(true).SetPrintExtendedTable(false).Run()
}
27 changes: 16 additions & 11 deletions artifactory/utils/repositoryutils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package utils

import (
"github.com/jfrog/gofrog/datastructures"
"golang.org/x/exp/slices"
"path"
"strings"

Expand Down Expand Up @@ -162,39 +164,42 @@ func GetFilteredBuildInfoRepositories(storageInfo *clientUtils.StorageInfo, incl
// includePatterns - Repositories inclusion wildcard pattern
// excludePatterns - Repositories exclusion wildcard pattern
func filterRepositoryNames(repoKeys *[]string, includePatterns, excludePatterns []string) ([]string, error) {
var included []string
includedRepos := datastructures.MakeSet[string]()
includeExcludeFilter := &IncludeExcludeFilter{
IncludePatterns: includePatterns,
ExcludePatterns: excludePatterns,
}
for _, repoKey := range *repoKeys {
repoIncluded, err := includeExcludeFilter.ShouldIncludeRepository(repoKey)
if err != nil {
return included, err
return nil, err
}
if repoIncluded {
included = append(included, repoKey)
includedRepos.Add(repoKey)
}
}
return included, nil
return includedRepos.ToSlice(), nil
}

type IncludeExcludeFilter struct {
IncludePatterns []string
ExcludePatterns []string
}

func (rf *IncludeExcludeFilter) ShouldIncludeRepository(repoKey string) (bool, error) {
rf.ExcludePatterns = append(rf.ExcludePatterns, blacklistedRepositories...)
return rf.ShouldIncludeItem(repoKey)
func (ief *IncludeExcludeFilter) ShouldIncludeRepository(repoKey string) (bool, error) {
if slices.Contains(blacklistedRepositories, repoKey) {
// This repository is blacklisted.
return false, nil
}
return ief.ShouldIncludeItem(repoKey)
}

func (rf *IncludeExcludeFilter) ShouldIncludeItem(item string) (bool, error) {
func (ief *IncludeExcludeFilter) ShouldIncludeItem(item string) (bool, error) {
// If includePattens is empty, include all.
repoIncluded := len(rf.IncludePatterns) == 0
repoIncluded := len(ief.IncludePatterns) == 0

// Check if this item name matches any include pattern.
for _, includePattern := range rf.IncludePatterns {
for _, includePattern := range ief.IncludePatterns {
matched, err := path.Match(includePattern, item)
if err != nil {
return false, err
Expand All @@ -210,7 +215,7 @@ func (rf *IncludeExcludeFilter) ShouldIncludeItem(item string) (bool, error) {
}

// Check if this item name matches any exclude pattern.
for _, excludePattern := range rf.ExcludePatterns {
for _, excludePattern := range ief.ExcludePatterns {
matched, err := path.Match(excludePattern, item)
if err != nil {
return false, err
Expand Down
8 changes: 4 additions & 4 deletions buildscripts/download-jars.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/sh

# Please use this script to download the JAR files for maven-dep-tree and gradle-dep-tree into the directory xray/audit/java/.
# Please use this script to download the JAR files for maven-dep-tree and gradle-dep-tree into the directory utils/java/.
# These JARs allow us to build Maven and Gradle dependency trees efficiently and without compilation.
# Learn more about them here:
# https://github.com/jfrog/gradle-dep-tree
# https://github.com/jfrog/maven-dep-tree

# Once you have updated the versions mentioned below, please execute this script from the root directory of the jfrog-cli-core to ensure the JAR files are updated.
GRADLE_DEP_TREE_VERSION="3.0.1"
# Changing this version also requires a change in mavenDepTreeVersion within xray/commands/audit/sca/java/mvn.go.
# Changing this version also requires a change in mavenDepTreeVersion within utils/java/mvn.go.
MAVEN_DEP_TREE_VERSION="1.1.0"

curl -fL https://releases.jfrog.io/artifactory/oss-release-local/com/jfrog/gradle-dep-tree/${GRADLE_DEP_TREE_VERSION}/gradle-dep-tree-${GRADLE_DEP_TREE_VERSION}.jar -o xray/commands/audit/sca/java/resources/gradle-dep-tree.jar
curl -fL https://releases.jfrog.io/artifactory/oss-release-local/com/jfrog/maven-dep-tree/${MAVEN_DEP_TREE_VERSION}/maven-dep-tree-${MAVEN_DEP_TREE_VERSION}.jar -o xray/commands/audit/sca/java/resources/maven-dep-tree.jar
curl -fL https://releases.jfrog.io/artifactory/oss-release-local/com/jfrog/gradle-dep-tree/${GRADLE_DEP_TREE_VERSION}/gradle-dep-tree-${GRADLE_DEP_TREE_VERSION}.jar -o utils/java/resources/gradle-dep-tree.jar
curl -fL https://releases.jfrog.io/artifactory/oss-release-local/com/jfrog/maven-dep-tree/${MAVEN_DEP_TREE_VERSION}/maven-dep-tree-${MAVEN_DEP_TREE_VERSION}.jar -o utils/java/resources/maven-dep-tree.jar
20 changes: 20 additions & 0 deletions common/cliutils/cli_consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cliutils

import ()

type CommandDomain string

const (
Rt CommandDomain = "rt"
Ds CommandDomain = "ds"
Xr CommandDomain = "xr"
Platform CommandDomain = "platform"
)

const (
// Common
Threads = 3

// Environment variables
JfrogCliAvoidDeprecationWarnings = "JFROG_CLI_AVOID_DEPRECATION_WARNINGS"
)
Loading

0 comments on commit 8129e67

Please sign in to comment.