Skip to content

Commit

Permalink
Convert remote repository numeric fields to pointers to avoid omitting (
Browse files Browse the repository at this point in the history
  • Loading branch information
sverdlov93 authored Sep 28, 2023
1 parent afee210 commit 622034e
Show file tree
Hide file tree
Showing 19 changed files with 219 additions and 202 deletions.
4 changes: 2 additions & 2 deletions access/services/accesstoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
"github.com/jfrog/jfrog-client-go/auth"
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
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"
Expand Down Expand Up @@ -83,14 +84,13 @@ func (ps *TokenService) addAccessTokenAuthorizationHeader(params CreateTokenPara
}

func createRefreshTokenRequestParams(p CreateTokenParams) (*CreateTokenParams, error) {
var trueValue = true
// Validate provided parameters
if p.RefreshToken == "" {
return nil, errorutils.CheckErrorf("error: trying to refresh token, but 'refresh_token' field wasn't provided. ")
}
params := NewCreateTokenParams(p)
// Set refresh required parameters
params.GrantType = "refresh_token"
params.Refreshable = &trueValue
params.Refreshable = clientutils.Pointer(true)
return &params, nil
}
14 changes: 7 additions & 7 deletions artifactory/services/remoterepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ type RemoteRepositoryBaseParams struct {
HardFail *bool `json:"hardFail,omitempty"`
Offline *bool `json:"offline,omitempty"`
StoreArtifactsLocally *bool `json:"storeArtifactsLocally,omitempty"`
SocketTimeoutMillis int `json:"socketTimeoutMillis,omitempty"`
SocketTimeoutMillis *int `json:"socketTimeoutMillis,omitempty"`
LocalAddress string `json:"localAddress,omitempty"`
RetrievalCachePeriodSecs int `json:"retrievalCachePeriodSecs,omitempty"`
MetadataRetrievalTimeoutSecs int `json:"metadataRetrievalTimeoutSecs,omitempty"`
MissedRetrievalCachePeriodSecs int `json:"missedRetrievalCachePeriodSecs,omitempty"`
UnusedArtifactsCleanupPeriodHours int `json:"unusedArtifactsCleanupPeriodHours,omitempty"`
AssumedOfflinePeriodSecs int `json:"assumedOfflinePeriodSecs,omitempty"`
RetrievalCachePeriodSecs *int `json:"retrievalCachePeriodSecs,omitempty"`
MetadataRetrievalTimeoutSecs *int `json:"metadataRetrievalTimeoutSecs,omitempty"`
MissedRetrievalCachePeriodSecs *int `json:"missedRetrievalCachePeriodSecs,omitempty"`
UnusedArtifactsCleanupPeriodHours *int `json:"unusedArtifactsCleanupPeriodHours,omitempty"`
AssumedOfflinePeriodSecs *int `json:"assumedOfflinePeriodSecs,omitempty"`
ShareConfiguration *bool `json:"shareConfiguration,omitempty"`
SynchronizeProperties *bool `json:"synchronizeProperties,omitempty"`
BlockMismatchingMimeTypes *bool `json:"blockMismatchingMimeTypes,omitempty"`
Expand All @@ -205,7 +205,7 @@ func NewRemoteRepositoryPackageParams(packageType string) RemoteRepositoryBasePa

type JavaPackageManagersRemoteRepositoryParams struct {
RemoteRepoChecksumPolicyType string `json:"remoteRepoChecksumPolicyType,omitempty"`
MaxUniqueSnapshots int `json:"maxUniqueSnapshots,omitempty"`
MaxUniqueSnapshots *int `json:"maxUniqueSnapshots,omitempty"`
FetchJarsEagerly *bool `json:"fetchJarsEagerly,omitempty"`
SuppressPomConsistencyChecks *bool `json:"suppressPomConsistencyChecks,omitempty"`
FetchSourcesEagerly *bool `json:"fetchSourcesEagerly,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/jfrog/jfrog-client-go
go 1.20

require (
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c
github.com/buger/jsonparser v1.1.1
github.com/forPelevin/gomoji v1.1.8
github.com/go-git/go-git/v5 v5.9.0
Expand Down Expand Up @@ -58,6 +58,6 @@ require (
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.20230928084830-478bd49f5d3e

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog dev
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ github.com/CycloneDX/cyclonedx-go v0.7.2/go.mod h1:K2bA+324+Og0X84fA8HhN2X066K7B
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg=
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c h1:kMFnB0vCcX7IL/m9Y5LO+KQYv+t1CQOiFe6+SV2J7bE=
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ=
github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/andybalholm/brotli v1.0.1 h1:KqhlKozYbRtJvsPrrEeXcO+N2l6NYT5A2QAFmSULpEc=
Expand Down 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.10 h1:uXnDLVxpqxoAMpXcki00QaBB+M2BoGMMpHODPkmmYOY=
github.com/jfrog/build-info-go v1.9.10/go.mod h1:ujJ8XQZMdT2tMkLSMJNyDd1pCY+duwHdjV+9or9FLIg=
github.com/jfrog/build-info-go v1.8.9-0.20230928084830-478bd49f5d3e h1:tWNlQScbapCz5/EBc+lKBBQcZ/3QLgM3tM3HBEtxCTs=
github.com/jfrog/build-info-go v1.8.9-0.20230928084830-478bd49f5d3e/go.mod h1:ujJ8XQZMdT2tMkLSMJNyDd1pCY+duwHdjV+9or9FLIg=
github.com/jfrog/gofrog v1.3.0 h1:o4zgsBZE4QyDbz2M7D4K6fXPTBJht+8lE87mS9bw7Gk=
github.com/jfrog/gofrog v1.3.0/go.mod h1:IFMc+V/yf7rA5WZ74CSbXe+Lgf0iApEQLxRZVzKRUR0=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
Expand Down
17 changes: 9 additions & 8 deletions tests/accessproject_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"github.com/jfrog/jfrog-client-go/utils"
"reflect"
"testing"

Expand Down Expand Up @@ -59,10 +60,10 @@ func testAccessProjectCreateUpdateDelete(t *testing.T) {
defer deleteProjectAndAssert(t, projectParams.ProjectDetails.ProjectKey)
projectParams.ProjectDetails.Description += "123"
projectParams.ProjectDetails.StorageQuotaBytes += 123
projectParams.ProjectDetails.SoftLimit = &trueValue
projectParams.ProjectDetails.AdminPrivileges.ManageMembers = &falseValue
projectParams.ProjectDetails.AdminPrivileges.ManageResources = &trueValue
projectParams.ProjectDetails.AdminPrivileges.IndexResources = &falseValue
projectParams.ProjectDetails.SoftLimit = utils.Pointer(true)
projectParams.ProjectDetails.AdminPrivileges.ManageMembers = utils.Pointer(false)
projectParams.ProjectDetails.AdminPrivileges.ManageResources = utils.Pointer(true)
projectParams.ProjectDetails.AdminPrivileges.IndexResources = utils.Pointer(false)
assert.NoError(t, testsAccessProjectService.Update(projectParams))
updatedProject, err := testsAccessProjectService.Get(projectParams.ProjectDetails.ProjectKey)
if assert.NoError(t, err) &&
Expand All @@ -83,17 +84,17 @@ func deleteProjectAndAssert(t *testing.T, projectKey string) {

func getTestProjectParams(projectKey string, projectName string) services.ProjectParams {
adminPrivileges := services.AdminPrivileges{
ManageMembers: &trueValue,
ManageResources: &falseValue,
IndexResources: &trueValue,
ManageMembers: utils.Pointer(true),
ManageResources: utils.Pointer(false),
IndexResources: utils.Pointer(true),
}
runId := getRunId()
runNumberSuffix := runId[len(runId)-3:]
projectDetails := services.Project{
DisplayName: projectName + runNumberSuffix,
Description: "My Test Project",
AdminPrivileges: &adminPrivileges,
SoftLimit: &falseValue,
SoftLimit: utils.Pointer(false),
StorageQuotaBytes: 1073741825, // Needs to be higher than 1073741824
ProjectKey: projectKey + runNumberSuffix, // Valid length: 2 <= ProjectKey <= 10
}
Expand Down
7 changes: 4 additions & 3 deletions tests/accesstokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tests
import (
"github.com/jfrog/jfrog-client-go/access/services"
"github.com/jfrog/jfrog-client-go/auth"
"github.com/jfrog/jfrog-client-go/utils"
"github.com/stretchr/testify/assert"
"testing"
)
Expand All @@ -29,7 +30,7 @@ func testCreateRefreshableToken(t *testing.T) {

func testAccessTokenWithReference(t *testing.T) {
tokenParams := createRefreshableAccessTokenParams(testExpiredInSeconds)
tokenParams.IncludeReferenceToken = &trueValue
tokenParams.IncludeReferenceToken = utils.Pointer(true)
token, err := testsAccessTokensService.CreateAccessToken(tokenParams)
assert.NoError(t, err)
assert.NotEqual(t, "", token.AccessToken, "Access token is empty")
Expand Down Expand Up @@ -58,15 +59,15 @@ func testRefreshTokenTest(t *testing.T) {
func createRefreshableAccessTokenParams(expiredIn int) services.CreateTokenParams {
tokenParams := services.CreateTokenParams{}
tokenParams.ExpiresIn = expiredIn
tokenParams.Refreshable = &trueValue
tokenParams.Refreshable = utils.Pointer(true)
tokenParams.Audience = "*@*"
return tokenParams
}

func createRefreshAccessTokenParams(token auth.CreateTokenResponseData) (refreshParams services.CreateTokenParams) {
refreshParams = services.CreateTokenParams{}
refreshParams.ExpiresIn = token.ExpiresIn
refreshParams.Refreshable = &trueValue
refreshParams.Refreshable = utils.Pointer(true)
refreshParams.GrantType = "refresh_token"
refreshParams.TokenType = "Bearer"
refreshParams.RefreshToken = token.RefreshToken
Expand Down
9 changes: 5 additions & 4 deletions tests/artifactoryfederatedrepository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tests

import (
"github.com/jfrog/gofrog/version"
"github.com/jfrog/jfrog-client-go/utils"
"testing"

"github.com/jfrog/jfrog-client-go/artifactory/services"
Expand Down Expand Up @@ -56,14 +57,14 @@ func setFederatedRepositoryBaseParams(params *services.FederatedRepositoryBasePa
setAdditionalRepositoryBaseParams(&params.AdditionalRepositoryBaseParams, isUpdate)
memberUrl := testsCreateFederatedRepositoryService.ArtDetails.GetUrl() + params.Key
if !isUpdate {
params.ArchiveBrowsingEnabled = &trueValue
params.ArchiveBrowsingEnabled = utils.Pointer(true)
params.Members = []services.FederatedRepositoryMember{
{Url: memberUrl, Enabled: &trueValue},
{Url: memberUrl, Enabled: utils.Pointer(true)},
}
} else {
params.ArchiveBrowsingEnabled = &falseValue
params.ArchiveBrowsingEnabled = utils.Pointer(false)
params.Members = []services.FederatedRepositoryMember{
{Url: memberUrl, Enabled: &trueValue},
{Url: memberUrl, Enabled: utils.Pointer(true)},
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions tests/artifactoryfederation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tests

import (
"github.com/jfrog/gofrog/version"
"github.com/jfrog/jfrog-client-go/utils"
"testing"

"github.com/jfrog/jfrog-client-go/artifactory/services"
Expand Down Expand Up @@ -29,9 +30,9 @@ func localConvertLocalToFederatedTest(t *testing.T) {
glp.Key = repoKey
glp.RepoLayoutRef = "simple-default"
glp.Description = "Generic Repo for jfrog-client-go federation-test"
glp.XrayIndex = &trueValue
glp.DownloadRedirect = &falseValue
glp.ArchiveBrowsingEnabled = &falseValue
glp.XrayIndex = utils.Pointer(true)
glp.DownloadRedirect = utils.Pointer(false)
glp.ArchiveBrowsingEnabled = utils.Pointer(false)

err := testsCreateLocalRepositoryService.Generic(glp)
if !assert.NoError(t, err, "Failed to create "+repoKey) {
Expand Down
9 changes: 5 additions & 4 deletions tests/artifactorygroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tests

import (
"fmt"
"github.com/jfrog/jfrog-client-go/utils"
"sort"
"testing"

Expand Down Expand Up @@ -41,8 +42,8 @@ func testUpdateGroup(t *testing.T) {
defer deleteGroupAndAssert(t, groupParams.GroupDetails.Name)
assert.NoError(t, err)
groupParams.GroupDetails.Description = "Changed description"
groupParams.GroupDetails.AutoJoin = &trueValue
groupParams.GroupDetails.AdminPrivileges = &falseValue
groupParams.GroupDetails.AutoJoin = utils.Pointer(true)
groupParams.GroupDetails.AdminPrivileges = utils.Pointer(false)
err = testGroupService.UpdateGroup(groupParams)
assert.NoError(t, err)
group, err := testGroupService.GetGroup(groupParams)
Expand Down Expand Up @@ -97,8 +98,8 @@ func getTestGroupParams(includeUsers bool) services.GroupParams {
groupDetails := services.Group{
Name: fmt.Sprintf("test-%s", getRunId()),
Description: "hello",
AutoJoin: &falseValue,
AdminPrivileges: &trueValue,
AutoJoin: utils.Pointer(false),
AdminPrivileges: utils.Pointer(true),
Realm: "internal",
RealmAttributes: "",
}
Expand Down
13 changes: 7 additions & 6 deletions tests/artifactorylocalrepository_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"github.com/jfrog/jfrog-client-go/utils"
"testing"

"github.com/jfrog/jfrog-client-go/artifactory/services"
Expand Down Expand Up @@ -48,9 +49,9 @@ func setLocalRepositoryBaseParams(params *services.LocalRepositoryBaseParams, is
setRepositoryBaseParams(&params.RepositoryBaseParams, isUpdate)
setAdditionalRepositoryBaseParams(&params.AdditionalRepositoryBaseParams, isUpdate)
if !isUpdate {
params.ArchiveBrowsingEnabled = &trueValue
params.ArchiveBrowsingEnabled = utils.Pointer(true)
} else {
params.ArchiveBrowsingEnabled = &falseValue
params.ArchiveBrowsingEnabled = utils.Pointer(false)
}
}

Expand Down Expand Up @@ -667,8 +668,8 @@ func localYumTest(t *testing.T) {
setLocalRepositoryBaseParams(&ylp.LocalRepositoryBaseParams, false)
yumRootDepth := 6
ylp.YumRootDepth = &yumRootDepth
ylp.CalculateYumMetadata = &trueValue
ylp.EnableFileListsIndexing = &trueValue
ylp.CalculateYumMetadata = utils.Pointer(true)
ylp.EnableFileListsIndexing = utils.Pointer(true)
ylp.YumGroupFileNames = "filename"

err := testsCreateLocalRepositoryService.Yum(ylp)
Expand All @@ -682,8 +683,8 @@ func localYumTest(t *testing.T) {

setLocalRepositoryBaseParams(&ylp.LocalRepositoryBaseParams, true)
*ylp.YumRootDepth = 18
ylp.CalculateYumMetadata = &falseValue
ylp.EnableFileListsIndexing = &falseValue
ylp.CalculateYumMetadata = utils.Pointer(false)
ylp.EnableFileListsIndexing = utils.Pointer(false)
ylp.YumGroupFileNames = ""

err = testsUpdateLocalRepositoryService.Yum(ylp)
Expand Down
21 changes: 11 additions & 10 deletions tests/artifactorypermissiontarget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tests
import (
"crypto/rand"
"fmt"
"github.com/jfrog/jfrog-client-go/utils"
"testing"

"github.com/jfrog/jfrog-client-go/artifactory/services"
Expand Down Expand Up @@ -164,15 +165,15 @@ func createRandomUser(t *testing.T) string {
Name: name,
Email: name + "@jfrog.com",
Password: "Password1*",
Admin: &falseValue,
Admin: utils.Pointer(false),
Realm: "internal",
ShouldInvite: &falseValue,
ProfileUpdatable: &trueValue,
DisableUIAccess: &falseValue,
InternalPasswordDisabled: &falseValue,
WatchManager: &falseValue,
ReportsManager: &falseValue,
PolicyManager: &falseValue,
ShouldInvite: utils.Pointer(false),
ProfileUpdatable: utils.Pointer(true),
DisableUIAccess: utils.Pointer(false),
InternalPasswordDisabled: utils.Pointer(false),
WatchManager: utils.Pointer(false),
ReportsManager: utils.Pointer(false),
PolicyManager: utils.Pointer(false),
}

err := testUserService.CreateUser(services.UserParams{
Expand Down Expand Up @@ -203,8 +204,8 @@ func createRandomGroup(t *testing.T) string {
groupDetails := services.Group{
Name: name,
Description: "hello",
AutoJoin: &falseValue,
AdminPrivileges: &falseValue,
AutoJoin: utils.Pointer(false),
AdminPrivileges: utils.Pointer(false),
Realm: "internal",
RealmAttributes: "",
}
Expand Down
Loading

0 comments on commit 622034e

Please sign in to comment.