Skip to content

Commit 9fb4156

Browse files
authored
Nuget - Add allowInsecureConnections flag for package sources (#1302)
1 parent b6efb65 commit 9fb4156

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

artifactory/commands/dotnet/dotnetcommand.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ The initial error is:
3030
)
3131

3232
type DotnetCommand struct {
33-
toolchainType dotnet.ToolchainType
34-
subCommand string
35-
argAndFlags []string
36-
repoName string
37-
solutionPath string
38-
useNugetV2 bool
39-
buildConfiguration *commonBuild.BuildConfiguration
40-
serverDetails *config.ServerDetails
33+
toolchainType dotnet.ToolchainType
34+
subCommand string
35+
argAndFlags []string
36+
repoName string
37+
solutionPath string
38+
useNugetV2 bool
39+
// By default, package sources are required to use HTTPS. This option allows sources to use HTTP.
40+
allowInsecureConnections bool
41+
buildConfiguration *commonBuild.BuildConfiguration
42+
serverDetails *config.ServerDetails
4143
}
4244

4345
func (dc *DotnetCommand) SetServerDetails(serverDetails *config.ServerDetails) *DotnetCommand {
@@ -70,6 +72,11 @@ func (dc *DotnetCommand) SetUseNugetV2(useNugetV2 bool) *DotnetCommand {
7072
return dc
7173
}
7274

75+
func (dc *DotnetCommand) SetAllowInsecureConnections(allowInsecureConnections bool) *DotnetCommand {
76+
dc.allowInsecureConnections = allowInsecureConnections
77+
return dc
78+
}
79+
7380
func (dc *DotnetCommand) SetArgAndFlags(argAndFlags []string) *DotnetCommand {
7481
dc.argAndFlags = argAndFlags
7582
return dc
@@ -242,7 +249,7 @@ func (dc *DotnetCommand) prepareConfigFileIfNeeded() (cleanup func() error, err
242249
return fileutils.RemoveTempDir(tempDirPath)
243250
}
244251

245-
configFile, err := InitNewConfig(tempDirPath, dc.repoName, dc.serverDetails, dc.useNugetV2)
252+
configFile, err := InitNewConfig(tempDirPath, dc.repoName, dc.serverDetails, dc.useNugetV2, dc.allowInsecureConnections)
246253
if err == nil {
247254
dc.argAndFlags = append(dc.argAndFlags, dc.GetToolchain().GetTypeFlagPrefix()+"configfile", configFile.Name())
248255
}
@@ -269,7 +276,7 @@ func getFlagValueIfExists(cmdFlag string, argAndFlags []string) (string, error)
269276
}
270277

271278
// InitNewConfig is used when neither of the flags were provided, and we need to init our own config.
272-
func InitNewConfig(configDirPath, repoName string, server *config.ServerDetails, useNugetV2 bool) (configFile *os.File, err error) {
279+
func InitNewConfig(configDirPath, repoName string, server *config.ServerDetails, useNugetV2, allowInsecureConnections bool) (configFile *os.File, err error) {
273280
// Initializing a new NuGet config file that NuGet will use into a temp file
274281
configFile, err = os.CreateTemp(configDirPath, configFilePattern)
275282
if errorutils.CheckError(err) != nil {
@@ -283,12 +290,12 @@ func InitNewConfig(configDirPath, repoName string, server *config.ServerDetails,
283290
// We would prefer to write the NuGet configuration using the `nuget add source` command,
284291
// but the NuGet configuration utility doesn't currently allow setting protocolVersion.
285292
// Until that is supported, the templated method must be used.
286-
err = addSourceToNugetTemplate(configFile, server, useNugetV2, repoName)
293+
err = addSourceToNugetTemplate(configFile, server, useNugetV2, repoName, allowInsecureConnections)
287294
return
288295
}
289296

290297
// Adds a source to the nuget config template
291-
func addSourceToNugetTemplate(configFile *os.File, server *config.ServerDetails, useNugetV2 bool, repoName string) error {
298+
func addSourceToNugetTemplate(configFile *os.File, server *config.ServerDetails, useNugetV2 bool, repoName string, allowInsecureConnections bool) error {
292299
sourceUrl, user, password, err := GetSourceDetails(server, repoName, useNugetV2)
293300
if err != nil {
294301
return err
@@ -301,7 +308,7 @@ func addSourceToNugetTemplate(configFile *os.File, server *config.ServerDetails,
301308
}
302309

303310
// Format the templates
304-
_, err = fmt.Fprintf(configFile, dotnet.ConfigFileFormat, sourceUrl, protoVer, user, password)
311+
_, err = fmt.Fprintf(configFile, dotnet.ConfigFileFormat, sourceUrl, protoVer, allowInsecureConnections, user, password)
305312
return err
306313
}
307314

artifactory/commands/dotnet/dotnetcommand_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestInitNewConfig(t *testing.T) {
7474
User: "user",
7575
Password: "pass",
7676
}
77-
configFile, err := InitNewConfig(tmpDir, repoName, server, false)
77+
configFile, err := InitNewConfig(tmpDir, repoName, server, false, true)
7878
assert.NoError(t, err)
7979
f, err := os.Open(configFile.Name())
8080
assert.NoError(t, err)
@@ -87,7 +87,7 @@ func TestInitNewConfig(t *testing.T) {
8787
assert.Equal(t, `<?xml version="1.0" encoding="utf-8"?>
8888
<configuration>
8989
<packageSources>
90-
<add key="JFrogCli" value="https://server.com/artifactory/api/nuget/v3/test-repo" protocolVersion="3" />
90+
<add key="JFrogCli" value="https://server.com/artifactory/api/nuget/v3/test-repo" protocolVersion="3" allowInsecureConnections="true"/>
9191
</packageSources>
9292
<packageSourceCredentials>
9393
<JFrogCli>
@@ -98,7 +98,7 @@ func TestInitNewConfig(t *testing.T) {
9898
</configuration>`, string(buf[:n]))
9999
server.Password = ""
100100
server.AccessToken = "abc123"
101-
configFile, err = InitNewConfig(tmpDir, repoName, server, true)
101+
configFile, err = InitNewConfig(tmpDir, repoName, server, true, false)
102102
assert.NoError(t, err)
103103
updatedConfigFile, err := os.Open(configFile.Name())
104104
assert.NoError(t, err)
@@ -111,7 +111,7 @@ func TestInitNewConfig(t *testing.T) {
111111
assert.Equal(t, `<?xml version="1.0" encoding="utf-8"?>
112112
<configuration>
113113
<packageSources>
114-
<add key="JFrogCli" value="https://server.com/artifactory/api/nuget/test-repo" protocolVersion="2" />
114+
<add key="JFrogCli" value="https://server.com/artifactory/api/nuget/test-repo" protocolVersion="2" allowInsecureConnections="false"/>
115115
</packageSources>
116116
<packageSourceCredentials>
117117
<JFrogCli>
@@ -164,11 +164,12 @@ func testPrepareDotnetBuildInfoModule(t *testing.T, subCommand string, flags []s
164164
}()
165165
module := createNewDotnetModule(t, tmpDir)
166166
cmd := DotnetCommand{
167-
toolchainType: dotnet.DotnetCore,
168-
subCommand: subCommand,
169-
argAndFlags: flags,
170-
buildConfiguration: buildUtils.NewBuildConfiguration("", "", "mod", ""),
171-
serverDetails: &config.ServerDetails{ArtifactoryUrl: "https://my-instance.jfrog.io"},
167+
toolchainType: dotnet.DotnetCore,
168+
subCommand: subCommand,
169+
argAndFlags: flags,
170+
buildConfiguration: buildUtils.NewBuildConfiguration("", "", "mod", ""),
171+
serverDetails: &config.ServerDetails{ArtifactoryUrl: "https://my-instance.jfrog.io"},
172+
allowInsecureConnections: true,
172173
}
173174
callbackFunc, err := cmd.prepareDotnetBuildInfoModule(module)
174175
if !assert.NoError(t, err) {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,6 @@ require (
9898

9999
// replace github.com/jfrog/jfrog-client-go => github.com/eyalbe4/jfrog-client-go v1.28.1-0.20241103083749-45c13ff7fe16
100100

101-
// replace github.com/jfrog/build-info-go => github.com/galusben/build-info-go v0.0.0-20240930113238-ac3b31030284
101+
replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20241121100855-e7a75ceee2bd
102102

103103
// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.3.3-0.20231223133729-ef57bd08cedc

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ github.com/jedib0t/go-pretty/v6 v6.6.1 h1:iJ65Xjb680rHcikRj6DSIbzCex2huitmc7bDtx
8989
github.com/jedib0t/go-pretty/v6 v6.6.1/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
9090
github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI=
9191
github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw=
92-
github.com/jfrog/build-info-go v1.10.5 h1:cW03JlPlKv7RMUU896uLUxyLWXAmCgR5Y5QX0fwgz0Q=
93-
github.com/jfrog/build-info-go v1.10.5/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
92+
github.com/jfrog/build-info-go v1.8.9-0.20241121100855-e7a75ceee2bd h1:PzxnJ1mjHIL4bAC4RPm87WnJ1TZXFBicyOhtIHRQH6g=
93+
github.com/jfrog/build-info-go v1.8.9-0.20241121100855-e7a75ceee2bd/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
9494
github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=
9595
github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4=
9696
github.com/jfrog/jfrog-client-go v1.48.0 h1:hx5B7+Wnobmzq4aFVZtALtbEVDFcjpn0Wb4q2m6H4KU=

0 commit comments

Comments
 (0)