Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config profile with repo API implementation #261

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a9094dc
added new GetConfigProfileByUrl func and changed name GetConfigProfil…
eranturgeman Dec 10, 2024
8563f52
updated test with new name
eranturgeman Dec 10, 2024
16200e4
improved service version check in GetConfigProfileByName to separate …
eranturgeman Dec 10, 2024
19c3864
added test to GetConfigProfileByUrl
eranturgeman Dec 10, 2024
1714ad2
redirect go mod to client-go pr
eranturgeman Dec 10, 2024
b150d44
update go mod
eranturgeman Dec 11, 2024
56fb1de
go mod
eranturgeman Dec 11, 2024
fc5caaa
fixing test files
eranturgeman Dec 12, 2024
2901566
fixed incorrectly passed repo url. fetching repo url by git client
eranturgeman Dec 12, 2024
d2d6006
comment on test that needs to be fixed
eranturgeman Dec 12, 2024
f16c205
deleting comment
eranturgeman Dec 15, 2024
c5801f5
fix test according to latest update on the expected response on POST …
eranturgeman Dec 15, 2024
10de716
changes GetConfigProfileByUrl to get the repo url and not fetching it…
eranturgeman Dec 15, 2024
17be3e4
update go.mod and delete unncessary files
eranturgeman Dec 15, 2024
5c51e45
update go.mod and delete unncessary files
eranturgeman Dec 15, 2024
0360f8d
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli-security int…
eranturgeman Dec 15, 2024
7aaec2f
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli-security int…
eranturgeman Dec 17, 2024
5c6c28c
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli-security int…
eranturgeman Dec 18, 2024
0bcc268
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli-security int…
eranturgeman Dec 21, 2024
373d40c
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli-security int…
eranturgeman Dec 22, 2024
3be780a
CR fixes
eranturgeman Dec 22, 2024
0305867
update dependencies to latest client-go and cli-core
eranturgeman Dec 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ require (
github.com/jfrog/froggit-go v1.16.2
github.com/jfrog/gofrog v1.7.6
github.com/jfrog/jfrog-apps-config v1.0.1
github.com/jfrog/jfrog-cli-core/v2 v2.57.0
github.com/jfrog/jfrog-client-go v1.48.2
github.com/jfrog/jfrog-cli-core/v2 v2.57.2
github.com/jfrog/jfrog-client-go v1.48.4
github.com/magiconair/properties v1.8.7
github.com/owenrumney/go-sarif/v2 v2.3.0
github.com/stretchr/testify v1.10.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=
github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4=
github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYLipdsOFMY=
github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w=
github.com/jfrog/jfrog-cli-core/v2 v2.57.0 h1:3ON0J6Sjc2+4HZrzh4eSbdciXx3sJsJUIJ3TPQXh/5c=
github.com/jfrog/jfrog-cli-core/v2 v2.57.0/go.mod h1:SThaC/fniC96oN8YgCsHjvOxp5rBM7IppuIybn1oxT0=
github.com/jfrog/jfrog-client-go v1.48.2 h1:YVAIiNWuBEa4NbWL54I+YzvXHaxoHDk532USDKTvgLU=
github.com/jfrog/jfrog-client-go v1.48.2/go.mod h1:1a7bmQHkRmPEza9wva2+WVrYzrGbosrMymq57kyG5gU=
github.com/jfrog/jfrog-cli-core/v2 v2.57.2 h1:2shy1CRWm/8yf6WWfVyAW3AdmryQiI73Tkhfb62vgPE=
github.com/jfrog/jfrog-cli-core/v2 v2.57.2/go.mod h1:sgi0gw96J00Yzx2cKG5xTG/x9XD0YiJbglJOnXUeaD0=
github.com/jfrog/jfrog-client-go v1.48.4 h1:uXvBr2ebFKpBRUhWgC9TSSJe32IbSYGlbDp9tDzBcaY=
github.com/jfrog/jfrog-client-go v1.48.4/go.mod h1:2ySOMva54L3EYYIlCBYBTcTgqfrrQ19gtpA/MWfA/ec=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
github.com/k0kubun/pp v3.0.1+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
Expand Down
20 changes: 18 additions & 2 deletions utils/validations/test_mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ func XscServer(t *testing.T, params MockServerParams) (*httptest.Server, *config

func getXscServerApiHandler(t *testing.T, params MockServerParams) func(w http.ResponseWriter, r *http.Request) {
apiUrlPart := "api/v1/"
if xscutils.IsXscXrayInnerService(params.XrayVersion) {
var isXrayAfterXscMigration bool
if isXrayAfterXscMigration = xscutils.IsXscXrayInnerService(params.XrayVersion); isXrayAfterXscMigration {
apiUrlPart = ""
}
return func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -153,7 +154,22 @@ func XrayServer(t *testing.T, params MockServerParams) (*httptest.Server, *confi
}
}
}
if !xscutils.IsXscXrayInnerService(params.XrayVersion) {

isXrayAfterXscMigration := xscutils.IsXscXrayInnerService(params.XrayVersion)
if strings.Contains(r.RequestURI, "/xsc/profile_repos") && isXrayAfterXscMigration {
assert.Equal(t, http.MethodPost, r.Method)
w.WriteHeader(http.StatusOK)
content, err := os.ReadFile("../../tests/testdata/other/configProfile/configProfileExample.json")
if !assert.NoError(t, err) {
return
}
_, err = w.Write(content)
if !assert.NoError(t, err) {
return
}
}

if !isXrayAfterXscMigration {
return
}
getXscServerApiHandler(t, params)(w, r)
Expand Down
25 changes: 22 additions & 3 deletions utils/xsc/configprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,37 @@ import (
"github.com/jfrog/jfrog-client-go/xsc/services"
)

func GetConfigProfile(xrayVersion, xscVersion string, serverDetails *config.ServerDetails, profileName string) (*services.ConfigProfile, error) {
func GetConfigProfileByName(xrayVersion, xscVersion string, serverDetails *config.ServerDetails, profileName string) (*services.ConfigProfile, error) {
// If Xray version >= 1.107.13 (After Xsc migration to Xray), xscVersion is 3.999.999 and will always suffice this condition
if err := clientutils.ValidateMinimumVersion(clientutils.Xsc, xscVersion, services.ConfigProfileMinXscVersion); err != nil {
log.Info("Minimal Xsc version required to utilize config profile is '%s'. All configurations will be induced from provided Env vars and files")
log.Info(fmt.Sprintf("Minimal Xsc version required to utilize config profile by url is '%s'. All configurations will be induced from provided Env vars and files", services.ConfigProfileMinXscVersion))
return nil, err
}

xscService, err := CreateXscService(xrayVersion, serverDetails)
if err != nil {
return nil, err
}
configProfile, err := xscService.GetConfigProfile(profileName)
configProfile, err := xscService.GetConfigProfileByName(profileName)
if err != nil {
err = fmt.Errorf("failed to get config profile '%s': %q", profileName, err)
}
return configProfile, err
}

func GetConfigProfileByUrl(xrayVersion string, serverDetails *config.ServerDetails, cloneRepoUrl string) (*services.ConfigProfile, error) {
if err := clientutils.ValidateMinimumVersion(clientutils.Xray, xrayVersion, services.ConfigProfileByUrlMinXrayVersion); err != nil {
log.Info(fmt.Sprintf("Minimal Xray version required to utilize config profile by url is '%s'. All configurations will be induced from provided Env vars and files", services.ConfigProfileByUrlMinXrayVersion))
return nil, err
}
xscService, err := CreateXscService(xrayVersion, serverDetails)
if err != nil {
return nil, err
}

configProfile, err := xscService.GetConfigProfileByUrl(cloneRepoUrl)
if err != nil {
err = fmt.Errorf("failed to get config profile for url '%s': %q", serverDetails.Url, err)
}
return configProfile, err
}
59 changes: 52 additions & 7 deletions utils/xsc/configprofile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,78 @@ import (
"github.com/stretchr/testify/assert"
)

func TestGetConfigProfile(t *testing.T) {
const testRepoUrl = "https://github.com/jfrog/test-repository.git"

func TestGetConfigProfileByName(t *testing.T) {
testCases := []struct {
name string
mockParams validations.MockServerParams
expectError bool
}{
{
name: "Deprecated XSC service",
name: "Deprecated XSC service - Valid request",
mockParams: validations.MockServerParams{XrayVersion: "3.0.0", XscVersion: services.ConfigProfileMinXscVersion},
},
{
name: "Xsc as inner service in Xray",
name: "Deprecated XSC service - Xsc version too low - error expected",
mockParams: validations.MockServerParams{XrayVersion: "3.0.0", XscVersion: "1.0.0"},
expectError: true,
},
{
name: "Xsc as inner service in Xray - valid request",
mockParams: validations.MockServerParams{XrayVersion: xscutils.MinXrayVersionXscTransitionToXray, XscVersion: services.ConfigProfileMinXscVersion},
},
}

for _, testcase := range testCases {
t.Run(testcase.name, func(t *testing.T) {
mockServer, serverDetails := validations.XscServer(t, testcase.mockParams)
defer mockServer.Close()

configProfile, err := GetConfigProfileByName(testcase.mockParams.XrayVersion, testcase.mockParams.XscVersion, serverDetails, validations.TestConfigProfileName)
if testcase.expectError {
assert.Error(t, err)
assert.Nil(t, configProfile)
return
}
// Validate results
assert.NoError(t, err)

profileFileContent, err := os.ReadFile("../../tests/testdata/other/configProfile/configProfileExample.json")
assert.NoError(t, err)

var configProfileForComparison services.ConfigProfile
err = json.Unmarshal(profileFileContent, &configProfileForComparison)
assert.NoError(t, err)

assert.Equal(t, &configProfileForComparison, configProfile)
})
}
}

func TestGetConfigProfileByUrl(t *testing.T) {
testCases := []struct {
name string
mockParams validations.MockServerParams
expectError bool
}{
{
name: "Expected error - Xsc version too low",
mockParams: validations.MockServerParams{XrayVersion: xscutils.MinXrayVersionXscTransitionToXray, XscVersion: "1.0.0"},
name: "Xray version too low - error expected",
mockParams: validations.MockServerParams{XrayVersion: "3.108.0"},
expectError: true,
},
{
name: "Valid request",
mockParams: validations.MockServerParams{XrayVersion: services.ConfigProfileByUrlMinXrayVersion},
},
}

for _, testcase := range testCases {
t.Run(testcase.name, func(t *testing.T) {
mockServer, serverDetails := validations.XscServer(t, testcase.mockParams)
mockServer, serverDetails := validations.XrayServer(t, testcase.mockParams)
defer mockServer.Close()

configProfile, err := GetConfigProfile(testcase.mockParams.XrayVersion, testcase.mockParams.XscVersion, serverDetails, validations.TestConfigProfileName)
configProfile, err := GetConfigProfileByUrl(testcase.mockParams.XrayVersion, serverDetails, testRepoUrl)
eranturgeman marked this conversation as resolved.
Show resolved Hide resolved
if testcase.expectError {
assert.Error(t, err)
assert.Nil(t, configProfile)
Expand Down
Loading