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

NuGet - Allow to set allowInsecureConnections package source attribute #2758

Merged
merged 22 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
25 changes: 23 additions & 2 deletions buildtools/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,18 @@ func NugetCmd(c *cli.Context) error {
return err
}

allowInsecureConnection, err := extractBoolFlagFromArgs(&filteredNugetArgs, "allow-insecure-connections")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need to add this flag to cli?
isn't it a nuget's flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a NuGet flag, but I wanted to add the ability for the users to control the flag.
Do you suggest something else?

if err != nil {
return err
}

nugetCmd := dotnet.NewNugetCommand()
nugetCmd.SetServerDetails(rtDetails).SetRepoName(targetRepo).SetBuildConfiguration(buildConfiguration).
SetBasicCommand(filteredNugetArgs[0]).SetUseNugetV2(useNugetV2)
nugetCmd.SetServerDetails(rtDetails).
SetRepoName(targetRepo).
SetBuildConfiguration(buildConfiguration).
SetBasicCommand(filteredNugetArgs[0]).
SetUseNugetV2(useNugetV2).
SetAllowInsecureConnections(allowInsecureConnection)
// Since we are using the values of the command's arguments and flags along the buildInfo collection process,
// we want to separate the actual NuGet basic command (restore/build...) from the arguments and flags
if len(filteredNugetArgs) > 1 {
Expand Down Expand Up @@ -1074,3 +1083,15 @@ func getTwineConfigPath() (configFilePath string, err error) {
}
return "", errorutils.CheckErrorf(getMissingConfigErrMsg("twine", "pip-config OR pipenv-config"))
}

// Extracts the boolean flag from the args and removes it from the args.
func extractBoolFlagFromArgs(filteredNugetArgs *[]string, flagName string) (value bool, err error) {
EyalDelarea marked this conversation as resolved.
Show resolved Hide resolved
var flagIndex int
var allowInsecureConnection bool
flagIndex, allowInsecureConnection, err = coreutils.FindBooleanFlag("--"+flagName, *filteredNugetArgs)
if err != nil {
return false, err
}
coreutils.RemoveFlagFromCommand(filteredNugetArgs, flagIndex, flagIndex)
return allowInsecureConnection, nil
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241113152357-24197a744331
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241114105558-ffd4d869d4b0

// replace github.com/jfrog/jfrog-cli-security => github.com/jfrog/jfrog-cli-security v1.12.5-0.20241107141149-42cf964808a1
replace github.com/jfrog/jfrog-cli-security => github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241114092834-aff9aaf573ba

// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240918081224-1c584cc334c7

// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20240918150101-ad5b10435a12
replace github.com/jfrog/build-info-go => github.com/EyalDelarea/build-info-go v0.0.0-20241114092335-1c47774e5ded

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog dev
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/CycloneDX/cyclonedx-go v0.9.0 h1:inaif7qD8bivyxp7XLgxUYtOXWtDez7+j72qKTMQTb8=
github.com/CycloneDX/cyclonedx-go v0.9.0/go.mod h1:NE/EWvzELOFlG6+ljX/QeMlVt9VKcTwu8u0ccsACEsw=
github.com/EyalDelarea/build-info-go v0.0.0-20241114092335-1c47774e5ded h1:GMCP2b4v6N/tKZBQIwtneO2CJEOmt741VGse5288Im4=
github.com/EyalDelarea/build-info-go v0.0.0-20241114092335-1c47774e5ded/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241114105558-ffd4d869d4b0 h1:KP/+ILK0qeTkV+YTG61o0QVKe6l/iczVi41u52qDcGY=
github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241114105558-ffd4d869d4b0/go.mod h1:Lj9khgWhazp6RoiBk/AJts3O3iaSM4x/3OqYUfKqL54=
github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241114092834-aff9aaf573ba h1:Q45EF0k22gMvkDJqWK+CVtufrw32nL/kkJ/AE/jhI0c=
github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241114092834-aff9aaf573ba/go.mod h1:5LBGwth7TXkEH8MO0JJXvpoRktMAV2BK7Q5nQePNrv4=
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
Expand Down Expand Up @@ -161,8 +167,6 @@ github.com/jedib0t/go-pretty/v6 v6.6.1 h1:iJ65Xjb680rHcikRj6DSIbzCex2huitmc7bDtx
github.com/jedib0t/go-pretty/v6 v6.6.1/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI=
github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw=
github.com/jfrog/build-info-go v1.10.5 h1:cW03JlPlKv7RMUU896uLUxyLWXAmCgR5Y5QX0fwgz0Q=
github.com/jfrog/build-info-go v1.10.5/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
github.com/jfrog/froggit-go v1.16.2 h1:F//S83iXH14qsCwYzv0zB2JtjS2pJVEsUoEmYA+37dQ=
github.com/jfrog/froggit-go v1.16.2/go.mod h1:5VpdQfAcbuyFl9x/x8HGm7kVk719kEtW/8YJFvKcHPA=
github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=
Expand All @@ -171,12 +175,8 @@ github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYL
github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w=
github.com/jfrog/jfrog-cli-artifactory v0.1.6 h1:bMfJsrLQJw0dZp4nqUf1xOmtY0rpCatW/I5q88x+fhQ=
github.com/jfrog/jfrog-cli-artifactory v0.1.6/go.mod h1:jbNb22ebtupcjdhrdGq0VBew2vWG6VUK04xxGNDfynE=
github.com/jfrog/jfrog-cli-core/v2 v2.56.8 h1:UexulAwRVN20VmYACijkTFYKqtUq5myE4okEgmUrorw=
github.com/jfrog/jfrog-cli-core/v2 v2.56.8/go.mod h1:RY74eDpw1WBxruSfZ0HO1ax7c1NAj+rbBgA/hVOJNME=
github.com/jfrog/jfrog-cli-platform-services v1.4.0 h1:g6A30+tOfXd1h6VASeNwH+5mhs5bPQJ0MFzZs/4nlvs=
github.com/jfrog/jfrog-cli-platform-services v1.4.0/go.mod h1:Ky4SDXuMeaiNP/5zMT1YSzIuXG+cNYYOl8BaEA7Awbc=
github.com/jfrog/jfrog-cli-security v1.12.5 h1:2JHPyapXuHQw/qEaElGxBUGrJCZlVFLXDdxkqhf10vE=
github.com/jfrog/jfrog-cli-security v1.12.5/go.mod h1:5LBGwth7TXkEH8MO0JJXvpoRktMAV2BK7Q5nQePNrv4=
github.com/jfrog/jfrog-client-go v1.48.0 h1:hx5B7+Wnobmzq4aFVZtALtbEVDFcjpn0Wb4q2m6H4KU=
github.com/jfrog/jfrog-client-go v1.48.0/go.mod h1:1a7bmQHkRmPEza9wva2+WVrYzrGbosrMymq57kyG5gU=
github.com/jszwec/csvutil v1.10.0 h1:upMDUxhQKqZ5ZDCs/wy+8Kib8rZR8I8lOR34yJkdqhI=
Expand Down
24 changes: 19 additions & 5 deletions nuget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func testNativeNugetDotnetResolve(t *testing.T, uniqueTests []testDescriptor, bu
return
}
t.Run(test.name, func(t *testing.T) {
testNugetCmd(t, projectPath, buildName, strconv.Itoa(buildNumber), test.expectedModules, test.args, test.expectedDependencies)
testNugetCmd(t, projectPath, buildName, strconv.Itoa(buildNumber), test.expectedModules, test.args, test.expectedDependencies, projectType.String())
})
}
cleanTestsHomeEnv()
Expand All @@ -107,17 +107,21 @@ func TestNuGetWithGlobalConfig(t *testing.T) {
assert.NoError(t, err)
err = createConfigFileForTest([]string{jfrogHomeDir}, tests.NugetRemoteRepo, "", t, project.Nuget, true)
assert.NoError(t, err)
testNugetCmd(t, projectPath, tests.NuGetBuildName, "1", []string{"packagesconfig"}, []string{"nuget", "restore"}, []int{6})
// allow insecure connection for testings to work with localhost server
testNugetCmd(t, projectPath, tests.NuGetBuildName, "1", []string{"packagesconfig"}, []string{"nuget", "restore"}, []int{6}, project.Nuget.String())

cleanTestsHomeEnv()
}

func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expectedModule, args []string, expectedDependencies []int) {
func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expectedModule, args []string, expectedDependencies []int, projectType string) {
wd, err := os.Getwd()
assert.NoError(t, err, "Failed to get current dir")
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
defer chdirCallback()

args = append(args, "--build-name="+buildName, "--build-number="+buildNumber)

allowInsecureConnectionForTests(projectType, &args)
err = runNuGet(t, args...)
if err != nil {
return
Expand Down Expand Up @@ -152,6 +156,15 @@ func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expe
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
}

// Add allow insecure connection for testings to work with localhost server
// dotNet also uses this cmd, and we want to apply this only for Nuget.
func allowInsecureConnectionForTests(projectType string, args *[]string) *[]string {
if projectType == project.Nuget.String() {
*args = append(*args, "--allow-insecure-connections")
}
return args
}

func assertNugetDependencies(t *testing.T, module buildInfo.Module, moduleName string) {
for _, dependency := range module.Dependencies {
switch dependency.Id {
Expand Down Expand Up @@ -224,10 +237,11 @@ func runInitNewConfig(t *testing.T, testSuite testInitNewConfigDescriptor, baseR
params := &dotnet.DotnetCommand{}
server := &config.ServerDetails{ArtifactoryUrl: baseRtUrl, User: "user", Password: "password"}
params.SetServerDetails(server).
SetUseNugetV2(testSuite.useNugetV2)
SetUseNugetV2(testSuite.useNugetV2).
SetAllowInsecureConnections(true)
// Prepare the config file with NuGet authentication

configFile, err := dotnet.InitNewConfig(tempDirPath, "", server, testSuite.useNugetV2)
configFile, err := dotnet.InitNewConfig(tempDirPath, "", server, testSuite.useNugetV2, true)
if err != nil {
assert.NoError(t, err)
return
Expand Down
9 changes: 7 additions & 2 deletions utils/cliutils/commandsflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ const (
npmDetailedSummary = npmPrefix + detailedSummary

// Unique nuget/dotnet config flags
nugetV2 = "nuget-v2"
nugetV2 = "nuget-v2"
allowInsecureConnections = "allow-insecure-connections"

// Unique go flags
noFallback = "no-fallback"
Expand Down Expand Up @@ -1161,6 +1162,10 @@ var flagsMap = map[string]cli.Flag{
Name: nugetV2,
Usage: "[Default: false] Set to true if you'd like to use the NuGet V2 protocol when restoring packages from Artifactory.` `",
},
allowInsecureConnections: cli.BoolFlag{
Name: allowInsecureConnections,
Usage: "[Default: false] Set to true if you wish to configure NuGet sources with unsecured connections. This is recommended for testing purposes only. ` `",
},
noFallback: cli.BoolTFlag{
Name: noFallback,
Usage: "[Default: false] Set to true to avoid downloading packages from the VCS, if they are missing in Artifactory.` `",
Expand Down Expand Up @@ -1882,7 +1887,7 @@ var commandFlags = map[string][]string{
global, serverIdResolve, repoResolve, nugetV2,
},
Nuget: {
buildName, buildNumber, module, Project,
buildName, buildNumber, module, Project, allowInsecureConnections,
},
DotnetConfig: {
global, serverIdResolve, repoResolve, nugetV2,
Expand Down
Loading