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 22, 2024
2 parents 5dd6e86 + f84756a commit 4f0f4b7
Show file tree
Hide file tree
Showing 34 changed files with 255 additions and 118 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 @@ -28,15 +28,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\.* ./...
20 changes: 10 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
labels: "safe to test"

- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

Expand All @@ -35,7 +35,7 @@ jobs:
go-version: 1.20.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 All @@ -60,12 +60,12 @@ jobs:
go-version: 1.20.x

- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- 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 Expand Up @@ -94,7 +94,7 @@ jobs:
runs-on: ${{ matrix.os }}-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

Expand All @@ -104,7 +104,7 @@ jobs:
go-version: 1.20.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 All @@ -119,7 +119,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

Expand All @@ -129,7 +129,7 @@ jobs:
go-version: 1.20.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 All @@ -149,12 +149,12 @@ jobs:
go-version: 1.20.x

- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- 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
5 changes: 4 additions & 1 deletion access/services/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ func (ps *ProjectService) GetAll() ([]Project, error) {
}
var projects []Project
err = json.Unmarshal(body, &projects)
return projects, errorutils.CheckError(err)
if err != nil {
return nil, errorutils.CheckErrorf("failed extracting projects list from payload: " + err.Error())
}
return projects, nil
}

func (ps *ProjectService) Create(params ProjectParams) error {
Expand Down
4 changes: 2 additions & 2 deletions artifactory/services/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func removeIfSymlink(localSymlinkPath string) error {
func createLocalSymlink(localPath, localFileName, symlinkArtifact string, symlinkChecksum bool, symlinkContentChecksum string, logMsgPrefix string) (err error) {
if symlinkChecksum && symlinkContentChecksum != "" {
if !fileutils.IsPathExists(symlinkArtifact, false) {
return errorutils.CheckErrorf("Symlink validation failed, target doesn't exist: " + symlinkArtifact)
return errorutils.CheckErrorf("symlink validation failed, target doesn't exist: " + symlinkArtifact)
}
file, err := os.Open(symlinkArtifact)
if err = errorutils.CheckError(err); err != nil {
Expand All @@ -453,7 +453,7 @@ func createLocalSymlink(localPath, localFileName, symlinkArtifact string, symlin
}
sha1 := checksumInfo[biutils.SHA1]
if sha1 != symlinkContentChecksum {
return errorutils.CheckErrorf("Symlink validation failed for target: " + symlinkArtifact)
return errorutils.CheckErrorf("symlink validation failed for target: " + symlinkArtifact)
}
}
localSymlinkPath := filepath.Join(localPath, localFileName)
Expand Down
2 changes: 1 addition & 1 deletion artifactory/services/fspatterns/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func GetRootPath(pattern, target, archiveTarget string, patternType utils.Patter
placeholderParentheses := getPlaceholderParentheses(pattern, target, archiveTarget)
rootPath := utils.GetRootPath(pattern, patternType, placeholderParentheses)
if !fileutils.IsPathExists(rootPath, preserveSymLink) {
return "", errorutils.CheckErrorf("Path does not exist: " + rootPath)
return "", errorutils.CheckErrorf("path does not exist: " + rootPath)
}

return rootPath, nil
Expand Down
2 changes: 1 addition & 1 deletion artifactory/services/go/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (gpc *GoPublishCommand) verifyCompatibleVersion(artifactoryVersion string)
ver := version.NewVersion(artifactoryVersion)
gpc.artifactoryVersion = artifactoryVersion
if !ver.AtLeast(propertiesApi) {
return errorutils.CheckErrorf("Unsupported version of Artifactory: %s\nSupports Artifactory version %s and above", artifactoryVersion, propertiesApi)
return errorutils.CheckErrorf("unsupported version of Artifactory: %s\nSupports Artifactory version %s and above", artifactoryVersion, propertiesApi)
}
return nil
}
Expand Down
12 changes: 12 additions & 0 deletions artifactory/services/localrepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ func (lrs *LocalRepositoryService) Swift(params SwiftLocalRepositoryParams) erro
return lrs.performRequest(params, params.Key)
}

func (lrs *LocalRepositoryService) Terraform(params TerraformLocalRepositoryParams) error {
return lrs.performRequest(params, params.Key)
}

func (lrs *LocalRepositoryService) Vagrant(params VagrantLocalRepositoryParams) error {
return lrs.performRequest(params, params.Key)
}
Expand Down Expand Up @@ -383,6 +387,14 @@ func NewSwiftLocalRepositoryParams() SwiftLocalRepositoryParams {
return SwiftLocalRepositoryParams{LocalRepositoryBaseParams: NewLocalRepositoryPackageParams("swift")}
}

type TerraformLocalRepositoryParams struct {
LocalRepositoryBaseParams
}

func NewTerraformLocalRepositoryParams() TerraformLocalRepositoryParams {
return TerraformLocalRepositoryParams{LocalRepositoryBaseParams: NewLocalRepositoryPackageParams("terraform")}
}

type VagrantLocalRepositoryParams struct {
LocalRepositoryBaseParams
}
Expand Down
16 changes: 16 additions & 0 deletions artifactory/services/remoterepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func (rrs *RemoteRepositoryService) Swift(params SwiftRemoteRepositoryParams) er
return rrs.performRequest(params, params.Key)
}

func (rrs *RemoteRepositoryService) Terraform(params TerraformRemoteRepositoryParams) error {
return rrs.performRequest(params, params.Key)
}

func (rrs *RemoteRepositoryService) Vcs(params VcsRemoteRepositoryParams) error {
return rrs.performRequest(params, params.Key)
}
Expand Down Expand Up @@ -475,6 +479,18 @@ func NewSwiftRemoteRepositoryParams() SwiftRemoteRepositoryParams {
return SwiftRemoteRepositoryParams{RemoteRepositoryBaseParams: NewRemoteRepositoryPackageParams("swift")}
}

type TerraformRemoteRepositoryParams struct {
RemoteRepositoryBaseParams
TerraformRegistryUrl string `json:"terraformRegistryUrl,omitempty"`
TerraformProvidersUrl string `json:"terraformProvidersUrl,omitempty"`
VcsType string `json:"vcsType,omitempty"`
VcsGitProvider string `json:"vcsGitProvider,omitempty"`
}

func NewTerraformRemoteRepositoryParams() TerraformRemoteRepositoryParams {
return TerraformRemoteRepositoryParams{RemoteRepositoryBaseParams: NewRemoteRepositoryPackageParams("terraform")}
}

type VcsRemoteRepositoryParams struct {
RemoteRepositoryBaseParams
VcsGitRemoteRepositoryParams
Expand Down
11 changes: 8 additions & 3 deletions artifactory/services/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ func getSaveTaskInContentWriterFunc(writersMap map[string]*ArchiveUploadData, up
}

func CollectFilesForUpload(uploadParams UploadParams, progressMgr ioutils.ProgressMgr, vcsCache *clientutils.VcsCache, dataHandlerFunc UploadDataHandlerFunc) error {
// Target Specifies the target path in Artifactory in the following format: <repository name>/<repository path>, so it cannot start with a slash.
// Remove leading slash if exists
uploadParams.SetTarget(strings.TrimPrefix(uploadParams.GetTarget(), "/"))

// Target Specifies the target path in Artifactory in the following format: <repository name>/<repository path>, so it cannot start with a slash.
// If the received target path has no slashes then we assume that it's '<repository name>/' and we add the missing slash.
if !strings.Contains(uploadParams.GetTarget(), "/") {
uploadParams.SetTarget(uploadParams.GetTarget() + "/")
}
Expand Down Expand Up @@ -265,15 +271,14 @@ func CollectFilesForUpload(uploadParams UploadParams, progressMgr ioutils.Progre
uploadData := UploadData{Artifact: artifact, TargetProps: props, BuildProps: buildProps}
incGeneralProgressTotal(progressMgr, uploadParams)
dataHandlerFunc(uploadData)
return err
return nil
}
if uploadParams.Ant {
convertAntPatternToRegexp(&uploadParams)
} else {
convertPatternToRegexp(&uploadParams)
}
err = scanFilesByPattern(uploadParams, rootPath, progressMgr, vcsCache, dataHandlerFunc)
return err
return scanFilesByPattern(uploadParams, rootPath, progressMgr, vcsCache, dataHandlerFunc)
}

// convertAntPatternToRegexp converts a given Ant pattern to a regular expression.
Expand Down
2 changes: 1 addition & 1 deletion artifactory/services/utils/aqlquerybuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func CreateAqlBodyForSpecWithPattern(params *CommonParams) (string, error) {
return "", err
}
if params.Transitive && !singleRepo {
return "", errorutils.CheckErrorf("When searching or downloading with the transitive setting, the pattern must include a single repository only, meaning wildcards are allowed only after the first slash.")
return "", errorutils.CheckErrorf("when searching or downloading with the transitive setting, the pattern must include a single repository only, meaning wildcards are allowed only after the first slash.")
}
includeRoot := strings.Count(searchPattern, "/") < 2
triplesSize := len(repoPathFileTriples)
Expand Down
4 changes: 2 additions & 2 deletions artifactory/services/utils/artifactoryutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func ParseNameAndVersion(identifier string, useLatestPolicy bool) (string, strin
log.Debug("No '" + Delimiter + "' is found in the build, build number is set to " + LatestBuildNumberKey)
return identifier, LatestBuildNumberKey, nil
} else {
return "", "", errorutils.CheckErrorf("No '" + Delimiter + "' is found in '" + identifier + "'")
return "", "", errorutils.CheckErrorf("no '" + Delimiter + "' is found in '" + identifier + "'")
}
}
name, version := "", ""
Expand All @@ -216,7 +216,7 @@ func ParseNameAndVersion(identifier string, useLatestPolicy bool) (string, strin
name = identifier
version = LatestBuildNumberKey
} else {
return "", "", errorutils.CheckErrorf("No delimiter char (" + Delimiter + ") without escaping char was found in '" + identifier + "'")
return "", "", errorutils.CheckErrorf("no delimiter char (" + Delimiter + ") without escaping char was found in '" + identifier + "'")
}
}
// Remove escape chars.
Expand Down
4 changes: 2 additions & 2 deletions artifactory/services/utils/parsebuildnamenumber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestBuildParsingBuildNumberWithOnlyEscapeChars(t *testing.T) {
func TestBundleParsingNoBundleVersion(t *testing.T) {
log.SetLogger(log.NewLogger(log.DEBUG, nil))
_, _, err := ParseNameAndVersion("CLI-Bundle-Name", false)
assert.EqualError(t, err, "No '/' is found in 'CLI-Bundle-Name'")
assert.EqualError(t, err, "no '/' is found in 'CLI-Bundle-Name'")
}

func TestBundleParsingBundleVersionProvided(t *testing.T) {
Expand Down Expand Up @@ -115,5 +115,5 @@ func TestBundleParsingBundleVersionWithEscapeCharsInTheBundleVersion(t *testing.

func TestBundleParsingBundleVersionWithOnlyEscapeChars(t *testing.T) {
_, _, err := ParseNameAndVersion("CLI-Bundle-Name\\/1\\/2\\/3\\/4", false)
assert.EqualError(t, err, "No delimiter char (/) without escaping char was found in 'CLI-Bundle-Name\\/1\\/2\\/3\\/4'")
assert.EqualError(t, err, "no delimiter char (/) without escaping char was found in 'CLI-Bundle-Name\\/1\\/2\\/3\\/4'")
}
4 changes: 2 additions & 2 deletions artifactory/services/utils/searchutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func FilterBottomChainResults(readerRecord SearchBasedContentItem, reader *conte
for newRecord := (reflect.New(recordType)).Interface(); reader.NextRecord(newRecord) == nil; newRecord = (reflect.New(recordType)).Interface() {
resultItem, ok := newRecord.(SearchBasedContentItem)
if !ok {
return nil, errorutils.CheckErrorf("Reader record is not search-based.")
return nil, errorutils.CheckErrorf("reader record is not search-based.")
}

if resultItem.GetName() == "." {
Expand Down Expand Up @@ -491,7 +491,7 @@ func FilterTopChainResults(readerRecord SearchBasedContentItem, reader *content.
for newRecord := (reflect.New(recordType)).Interface(); reader.NextRecord(newRecord) == nil; newRecord = (reflect.New(recordType)).Interface() {
resultItem, ok := newRecord.(SearchBasedContentItem)
if !ok {
return nil, errorutils.CheckErrorf("Reader record is not search-based.")
return nil, errorutils.CheckErrorf("reader record is not search-based.")
}

if resultItem.GetName() == "." {
Expand Down
26 changes: 26 additions & 0 deletions artifactory/services/virtualrepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func (vrs *VirtualRepositoryService) Chef(params ChefVirtualRepositoryParams) er
return vrs.performRequest(params, params.Key)
}

func (vrs *VirtualRepositoryService) Composer(params ComposerVirtualRepositoryParams) error {
return vrs.performRequest(params, params.Key)
}

func (vrs *VirtualRepositoryService) Conan(params ConanVirtualRepositoryParams) error {
return vrs.performRequest(params, params.Key)
}
Expand Down Expand Up @@ -123,6 +127,10 @@ func (vrs *VirtualRepositoryService) Swift(params SwiftVirtualRepositoryParams)
return vrs.performRequest(params, params.Key)
}

func (vrs *VirtualRepositoryService) Terraform(params TerraformVirtualRepositoryParams) error {
return vrs.performRequest(params, params.Key)
}

func (vrs *VirtualRepositoryService) Yum(params YumVirtualRepositoryParams) error {
return vrs.performRequest(params, params.Key)
}
Expand Down Expand Up @@ -181,6 +189,15 @@ func NewChefVirtualRepositoryParams() ChefVirtualRepositoryParams {
return ChefVirtualRepositoryParams{VirtualRepositoryBaseParams: NewVirtualRepositoryPackageParams("chef")}
}

type ComposerVirtualRepositoryParams struct {
VirtualRepositoryBaseParams
CommonCacheVirtualRepositoryParams
}

func NewComposerVirtualRepositoryParams() ComposerVirtualRepositoryParams {
return ComposerVirtualRepositoryParams{VirtualRepositoryBaseParams: NewVirtualRepositoryPackageParams("composer")}
}

type ConanVirtualRepositoryParams struct {
VirtualRepositoryBaseParams
CommonCacheVirtualRepositoryParams
Expand Down Expand Up @@ -371,6 +388,15 @@ func NewSwiftVirtualRepositoryParams() SwiftVirtualRepositoryParams {
return SwiftVirtualRepositoryParams{VirtualRepositoryBaseParams: NewVirtualRepositoryPackageParams("swift")}
}

type TerraformVirtualRepositoryParams struct {
VirtualRepositoryBaseParams
CommonCacheVirtualRepositoryParams
}

func NewTerraformVirtualRepositoryParams() TerraformVirtualRepositoryParams {
return TerraformVirtualRepositoryParams{VirtualRepositoryBaseParams: NewVirtualRepositoryPackageParams("terraform")}
}

type YumVirtualRepositoryParams struct {
VirtualRepositoryBaseParams
CommonCacheVirtualRepositoryParams
Expand Down
2 changes: 1 addition & 1 deletion artifactory/usage/reportusage.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (rua *ReportUsageAttribute) isEmpty() bool {
func validateAndGetUsageServerInfo(serviceManager artifactory.ArtifactoryServicesManager) (url string, clientDetails httputils.HttpClientDetails, err error) {
config := serviceManager.GetConfig()
if config == nil {
err = errorutils.CheckErrorf("Expected full config, but no configuration exists.")
err = errorutils.CheckErrorf("expected full config, but no configuration exists.")
return
}
rtDetails := config.GetServiceDetails()
Expand Down
4 changes: 2 additions & 2 deletions auth/authutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func extractPayloadFromAccessToken(token string) (TokenPayload, error) {
var tokenPayload TokenPayload
err = json.Unmarshal(payload, &tokenPayload)
if err != nil {
return TokenPayload{}, errorutils.CheckErrorf("failed extracting payload from the provided access-token. " + err.Error())
return TokenPayload{}, errorutils.CheckErrorf("failed extracting payload from the provided access-token: " + err.Error())
}
err = setAudienceManually(&tokenPayload, payload)
return tokenPayload, err
Expand All @@ -56,7 +56,7 @@ func setAudienceManually(tokenPayload *TokenPayload, payload []byte) error {
allValuesMap := make(map[string]interface{})
err := json.Unmarshal(payload, &allValuesMap)
if err != nil {
return errorutils.CheckErrorf("Failed extracting audience from payload. " + err.Error())
return errorutils.CheckErrorf("failed extracting audience from payload: " + err.Error())
}
aud, exists := allValuesMap["aud"]
if !exists {
Expand Down
2 changes: 1 addition & 1 deletion auth/servicedetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (ccf *CommonConfigFields) GetClient() *jfroghttpclient.JfrogHttpClient {
}

func (ccf *CommonConfigFields) SetUrl(url string) {
ccf.Url = url
ccf.Url = utils.AddTrailingSlashIfNeeded(url)
}

func (ccf *CommonConfigFields) SetUser(user string) {
Expand Down

0 comments on commit 4f0f4b7

Please sign in to comment.