Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas committed Nov 8, 2023
2 parents 21998b7 + 79a2b21 commit dc27aae
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 16 deletions.
12 changes: 8 additions & 4 deletions artifactory/services/fspatterns/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// Return all the existing paths of the provided root path
func ListFiles(rootPath string, isRecursive, includeDirs, isSymlink bool, excludePathPattern string) ([]string, error) {
func ListFiles(rootPath string, isRecursive, includeDirs, excludeWithRelativePath, isSymlink bool, excludePathPattern string) ([]string, error) {
var paths []string
var err error
if isRecursive {
Expand All @@ -26,7 +26,11 @@ func ListFiles(rootPath string, isRecursive, includeDirs, isSymlink bool, exclud
if err != nil {
return paths, err
}
return filterFiles(paths, excludePathPattern)
var rootFilter string
if excludeWithRelativePath {
rootFilter = rootPath
}
return filterFiles(rootFilter, paths, excludePathPattern)
}

// Transform to regexp and prepare Exclude patterns to be used, exclusion patterns must be absolute paths.
Expand All @@ -49,13 +53,13 @@ func PrepareExcludePathPattern(exclusions []string, patternType utils.PatternTyp
return excludePathPattern
}

func filterFiles(files []string, excludePathPattern string) (filteredFiles []string, err error) {
func filterFiles(rootPath string, files []string, excludePathPattern string) (filteredFiles []string, err error) {
var excludedPath bool
for i := 0; i < len(files); i++ {
if files[i] == "." {
continue
}
excludedPath, err = isPathExcluded(files[i], excludePathPattern)
excludedPath, err = isPathExcluded(strings.TrimPrefix(files[i], rootPath), excludePathPattern)
if err != nil {
return
}
Expand Down
11 changes: 9 additions & 2 deletions artifactory/services/fspatterns/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ func TestFilterFiles(t *testing.T) {
data := []struct {
files []string
ExcludePattern string
root string
result []string
}{
{[]string{"file1", filepath.Join("dir", "file1"), "file2.zip"}, "^*.zip$", []string{"file1", filepath.Join("dir", "file1")}},
{[]string{"file1", filepath.Join("dir", "file1"), "file2.zip"}, "^*.zip$", "", []string{"file1", filepath.Join("dir", "file1")}},
{[]string{
"file1",
"test.zip",
filepath.Join("test", "file1"),
filepath.Join("dir", "test", "should-be-filter"),
}, "(^.*test.*$)", "test", []string{"file1", "test.zip", filepath.Join("test", "file1")}},
}
for _, d := range data {
got, err := filterFiles(d.files, d.ExcludePattern)
got, err := filterFiles(d.root, d.files, d.ExcludePattern)
assert.NoError(t, err)
assert.Len(t, got, len(d.result))
assert.Contains(t, got, d.files[0])
Expand Down
2 changes: 1 addition & 1 deletion artifactory/services/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func scanFilesByPattern(uploadParams UploadParams, rootPath string, progressMgr
if errorutils.CheckError(err) != nil {
return err
}
paths, err := fspatterns.ListFiles(rootPath, uploadParams.IsRecursive(), uploadParams.IsIncludeDirs(), uploadParams.IsSymlink(), excludePathPattern)
paths, err := fspatterns.ListFiles(rootPath, uploadParams.IsRecursive(), uploadParams.IsIncludeDirs(), false, uploadParams.IsSymlink(), excludePathPattern)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/go-git/go-git/v5 v5.9.0
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/gookit/color v1.5.4
github.com/jfrog/build-info-go v1.9.13
github.com/jfrog/build-info-go v1.9.15
github.com/jfrog/gofrog v1.3.1
github.com/mholt/archiver/v3 v3.5.1
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jfrog/build-info-go v1.9.13 h1:OeoGzPVK/O4TOUYk35uL4bXg/hleyqMrjGjjmyLOYrg=
github.com/jfrog/build-info-go v1.9.13/go.mod h1:ujJ8XQZMdT2tMkLSMJNyDd1pCY+duwHdjV+9or9FLIg=
github.com/jfrog/build-info-go v1.9.15 h1:DN7DKZq6H5FlHfL3Lu8fo4t2INgczRgT09dJiZjJ1oo=
github.com/jfrog/build-info-go v1.9.15/go.mod h1:XVFk2rCYhIdc7+hIGE8TC3le5PPM+xYHU22udoE2b7Q=
github.com/jfrog/gofrog v1.3.1 h1:QqAwQXCVReT724uga1AYqG/ZyrNQ6f+iTxmzkb+YFQk=
github.com/jfrog/gofrog v1.3.1/go.mod h1:IFMc+V/yf7rA5WZ74CSbXe+Lgf0iApEQLxRZVzKRUR0=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
Expand Down
4 changes: 4 additions & 0 deletions http/httpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func (jc *HttpClient) GetRetries() int {
return jc.retries
}

func (jc *HttpClient) GetClient() *http.Client {
return jc.client
}

func (jc *HttpClient) GetRetryWaitTime() int {
return jc.retryWaitMilliSecs
}
Expand Down
38 changes: 33 additions & 5 deletions utils/usage/reportusage.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package usage

import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"

"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
"github.com/jfrog/jfrog-client-go/http/httpclient"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/io/httputils"
"github.com/jfrog/jfrog-client-go/utils/log"
)

const (
Expand Down Expand Up @@ -51,11 +53,37 @@ func CreateUsageData(productId, accountId, clientId string, features ...string)
}

func sendRequestToEcosystemService(content []byte) (resp *http.Response, respBody []byte, err error) {
client, req, err := createEcosystemRequestInfo(content)
if err != nil {
return
}
log.Debug(fmt.Sprintf("Sending HTTP %s request to: %s", req.Method, req.URL))
resp, err = client.Do(req)
err = errorutils.CheckError(err)
if err != nil {
return
}
if resp == nil {
err = errorutils.CheckErrorf("Ecosystem-Usage Received empty response from server")
return
}
defer func() {
if resp.Body != nil {
err = errors.Join(err, errorutils.CheckError(resp.Body.Close()))
}
}()
respBody, _ = io.ReadAll(resp.Body)
return
}

func createEcosystemRequestInfo(content []byte) (c *http.Client, req *http.Request, err error) {
var client *httpclient.HttpClient
if client, err = httpclient.ClientBuilder().Build(); err != nil {
return
}
details := httputils.HttpClientDetails{}
utils.AddHeader("Content-Type", "application/json", &details.Headers)
return client.SendPost(ecosystemUsageApiPath, content, details, "Ecosystem-Usage")
if req, err = http.NewRequest(http.MethodPost, ecosystemUsageApiPath, bytes.NewBuffer(content)); err != nil {
return
}
req.Header.Set("Content-Type", "application/json")
return client.GetClient(), req, errorutils.CheckError(err)
}
2 changes: 1 addition & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
const (
Development = "development"
Agent = "jfrog-client-go"
Version = "1.34.3"
Version = "1.34.4"
)

type MinVersionProduct string
Expand Down

0 comments on commit dc27aae

Please sign in to comment.