Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/jfrog/jfrog-client-go into j…
Browse files Browse the repository at this point in the history
…f-access-token
  • Loading branch information
RobiNino committed Sep 14, 2023
2 parents 8558da7 + c396cb9 commit e562552
Show file tree
Hide file tree
Showing 22 changed files with 365 additions and 162 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@
- [Promoting a Release Bundle](#promoting-a-release-bundle)
- [Get Release Bundle Creation Status](#get-release-bundle-creation-status)
- [Get Release Bundle Promotion Status](#get-release-bundle-promotion-status)
- [Distribute Release Bundle](#distribute-release-bundle)
- [Delete Release Bundle](#delete-release-bundle)
- [Remote Delete Release Bundle](#remote-delete-release-bundle)

## General

Expand Down Expand Up @@ -2468,6 +2470,27 @@ projectKey := "default"
resp, err := serviceManager.GetReleaseBundlePromotionStatus(rbDetails, projectKey, createdMillis, sync)
```
#### Distribute Release Bundle
```go
rules := &distribution.DistributionCommonParams{
SiteName: "*",
CityName: "*",
CountryCodes: []string{"*"},
}
params := distribution.NewDistributeReleaseBundleParams("rbName", "rbVersion")
params.DistributionRules = append(params.DistributionRules, rules)

autoCreateRepo := true

pathMapping := services.PathMapping{
Pattern: "(*)/(*)",
Target: "{1}/target/{2}",
}

resp, err := serviceManager.DistributeReleaseBundle(params, autoCreateRepo, pathMapping)
```
#### Delete Release Bundle
```go
Expand All @@ -2481,3 +2504,19 @@ params.Async = true

resp, err := serviceManager.DeleteReleaseBundle(rbDetails, params)
```
#### Remote Delete Release Bundle
```go
rules := &distribution.DistributionCommonParams{
SiteName: "*",
CityName: "*",
CountryCodes: []string{"*"},
}
params := distribution.NewDistributeReleaseBundleParams("rbName", "rbVersion")
params.DistributionRules = append(params.DistributionRules, rules)

dryRun := true

resp, err := serviceManager.RemoteDeleteReleaseBundle(params, dryRun)
```
29 changes: 14 additions & 15 deletions artifactory/services/utils/tests/xray/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -1415,21 +1415,20 @@ const BuildScanResultsResponse = `
}
`


var MapReportIdEndpoint = map[int]string {
777: VulnerabilitiesEndpoint,
888: LicensesEndpoint,
var MapReportIdEndpoint = map[int]string{
777: VulnerabilitiesEndpoint,
888: LicensesEndpoint,
}

var MapResponse = map[string]map[string]string {
VulnerabilitiesEndpoint: {
"XrayReportRequest": VulnerabilityXrayReportRequestResponse,
"ReportStatus": VulnerabilityReportStatusResponse,
"ReportDetails": VulnerabilityReportDetailsResponse,
},
LicensesEndpoint: {
"XrayReportRequest": LicensesXrayReportRequestResponse,
"ReportStatus": LicensesReportStatusResponse,
"ReportDetails": LicensesReportDetailsResponse,
},
var MapResponse = map[string]map[string]string{
VulnerabilitiesEndpoint: {
"XrayReportRequest": VulnerabilityXrayReportRequestResponse,
"ReportStatus": VulnerabilityReportStatusResponse,
"ReportDetails": VulnerabilityReportDetailsResponse,
},
LicensesEndpoint: {
"XrayReportRequest": LicensesXrayReportRequestResponse,
"ReportStatus": LicensesReportStatusResponse,
"ReportDetails": LicensesReportDetailsResponse,
},
}
4 changes: 2 additions & 2 deletions artifactory/services/utils/tests/xray/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func reportHandler(w http.ResponseWriter, r *http.Request) {
log.Error(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}

return
}
case http.MethodPost:
Expand Down Expand Up @@ -114,7 +114,7 @@ func reportHandler(w http.ResponseWriter, r *http.Request) {
}
case http.MethodDelete:
if numSegments == 0 {
_, err := fmt.Fprint(w, XrayReportDeleteResponse)
_, err := fmt.Fprint(w, XrayReportDeleteResponse)
if err != nil {
log.Error(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down
3 changes: 0 additions & 3 deletions artifactory/usage/reportusage.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
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"
"github.com/jfrog/jfrog-client-go/utils/log"
)

const minArtifactoryVersion = "6.9.0"
Expand Down Expand Up @@ -42,12 +41,10 @@ func validateAndGetUsageServerInfo(serviceManager artifactory.ArtifactoryService
return
}
if e := clientutils.ValidateMinimumVersion(clientutils.Artifactory, artifactoryVersion, minArtifactoryVersion); e != nil {
log.Debug("Usage Report:", e.Error())
return
}
url, err = clientutils.BuildUrl(rtDetails.GetUrl(), "api/system/usage", make(map[string]string))
if err != nil {
err = errors.New(err.Error())
return
}
clientDetails = rtDetails.CreateHttpClientDetails()
Expand Down
28 changes: 0 additions & 28 deletions artifactory/usage/reportusage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,10 @@ package usage

import (
"fmt"
"github.com/jfrog/jfrog-client-go/utils"
"github.com/stretchr/testify/assert"
"testing"
)

func TestIsVersionCompatible(t *testing.T) {
tests := []struct {
artifactoryVersion string
expectedResult bool
}{
{"6.5.0", false},
{"6.2.0", false},
{"5.9.0", false},
{"6.0.0", false},
{"6.6.0", false},
{"6.9.0", true},
{utils.Development, true},
{"6.10.2", true},
{"6.15.2", true},
}
for _, test := range tests {
t.Run(test.artifactoryVersion, func(t *testing.T) {
err := utils.ValidateMinimumVersion(utils.Xray, test.artifactoryVersion, minArtifactoryVersion)
if test.expectedResult {
assert.NoError(t, err)
} else {
assert.ErrorContains(t, err, fmt.Sprintf(utils.MinimumVersionMsg, utils.Xray, test.artifactoryVersion, minArtifactoryVersion))
}
})
}
}

func TestReportUsageJson(t *testing.T) {
type reportUsageTestCase struct {
productId string
Expand Down
9 changes: 4 additions & 5 deletions auth/authutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,10 @@ type TokenPayload struct {
}

// Refreshable Tokens Constants.
// Artifactory's refresh token mechanism creates tokens that expire in 60 minutes. We want to refresh them when 10 minutes are left.
var RefreshArtifactoryTokenBeforeExpiryMinutes = int64(10)

// RefreshBeforeExpiryMinutes Artifactory's refresh token mechanism creates tokens that expired in 60 minutes. We want to refresh them after 50 minutes (when 10 minutes left)
var RefreshBeforeExpiryMinutes = int64(10)

// InviteRefreshBeforeExpiryMinutes Invitations mechanism creates tokens that are valid for 1 year. We want to refresh the token every 50 minutes.
var InviteRefreshBeforeExpiryMinutes = int64(365*24*60 - 50)
// Platform's access token are created with 1 year expiry. We want to refresh the token a week before expiry.
var RefreshPlatformTokenBeforeExpiryMinutes = int64(7 * 24 * 60)

const WaitBeforeRefreshSeconds = 15
2 changes: 1 addition & 1 deletion auth/servicedetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func SshTokenRefreshPreRequestInterceptor(fields *CommonConfigFields, httpClient
}
curToken := httpClientDetails.Headers["Authorization"]
timeLeft, err := GetTokenMinutesLeft(curToken)
if err != nil || timeLeft > RefreshBeforeExpiryMinutes {
if err != nil || timeLeft > RefreshArtifactoryTokenBeforeExpiryMinutes {
return err
}

Expand Down
23 changes: 12 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ require (
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371
github.com/buger/jsonparser v1.1.1
github.com/forPelevin/gomoji v1.1.8
github.com/go-git/go-git/v5 v5.8.1
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.9
github.com/jfrog/build-info-go v1.9.10
github.com/jfrog/gofrog v1.3.0
github.com/mholt/archiver/v3 v3.5.1
github.com/stretchr/testify v1.8.4
github.com/xanzy/ssh-agent v0.3.3
golang.org/x/crypto v0.12.0
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
golang.org/x/term v0.11.0
golang.org/x/crypto v0.13.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/term v0.12.0
)

require (
Expand All @@ -26,11 +26,12 @@ require (
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/andybalholm/brotli v1.0.1 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/snappy v0.0.2 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
Expand All @@ -50,13 +51,13 @@ require (
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/tools v0.13.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20230905120411-62d1bdd4eb38
// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20230905120411-62d1bdd4eb38

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog dev
// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog dev
Loading

0 comments on commit e562552

Please sign in to comment.