Skip to content

Commit b39d0cc

Browse files
authored
Merge branch 'jfrog:master' into feature/RTDEV-50692
2 parents 10fd035 + 5a3c2ae commit b39d0cc

File tree

6 files changed

+96
-31
lines changed

6 files changed

+96
-31
lines changed

artifactory/commands/dotnet/dotnetcommand.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import (
1919
)
2020

2121
const (
22-
SourceName = "JFrogArtifactory"
22+
// SourceName should match the one in the config file template.
23+
SourceName = "JFrogCli"
2324
configFilePattern = "jfrog.cli.nuget."
2425

2526
dotnetTestError = `the command failed with an error.
@@ -30,14 +31,16 @@ The initial error is:
3031
)
3132

3233
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
34+
toolchainType dotnet.ToolchainType
35+
subCommand string
36+
argAndFlags []string
37+
repoName string
38+
solutionPath string
39+
useNugetV2 bool
40+
// By default, package sources are required to use HTTPS. This option allows sources to use HTTP.
41+
allowInsecureConnections bool
42+
buildConfiguration *commonBuild.BuildConfiguration
43+
serverDetails *config.ServerDetails
4144
}
4245

4346
func (dc *DotnetCommand) SetServerDetails(serverDetails *config.ServerDetails) *DotnetCommand {
@@ -70,6 +73,11 @@ func (dc *DotnetCommand) SetUseNugetV2(useNugetV2 bool) *DotnetCommand {
7073
return dc
7174
}
7275

76+
func (dc *DotnetCommand) SetAllowInsecureConnections(allowInsecureConnections bool) *DotnetCommand {
77+
dc.allowInsecureConnections = allowInsecureConnections
78+
return dc
79+
}
80+
7381
func (dc *DotnetCommand) SetArgAndFlags(argAndFlags []string) *DotnetCommand {
7482
dc.argAndFlags = argAndFlags
7583
return dc
@@ -242,7 +250,7 @@ func (dc *DotnetCommand) prepareConfigFileIfNeeded() (cleanup func() error, err
242250
return fileutils.RemoveTempDir(tempDirPath)
243251
}
244252

245-
configFile, err := InitNewConfig(tempDirPath, dc.repoName, dc.serverDetails, dc.useNugetV2)
253+
configFile, err := InitNewConfig(tempDirPath, dc.repoName, dc.serverDetails, dc.useNugetV2, dc.allowInsecureConnections)
246254
if err == nil {
247255
dc.argAndFlags = append(dc.argAndFlags, dc.GetToolchain().GetTypeFlagPrefix()+"configfile", configFile.Name())
248256
}
@@ -269,7 +277,7 @@ func getFlagValueIfExists(cmdFlag string, argAndFlags []string) (string, error)
269277
}
270278

271279
// 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) {
280+
func InitNewConfig(configDirPath, repoName string, server *config.ServerDetails, useNugetV2, allowInsecureConnections bool) (configFile *os.File, err error) {
273281
// Initializing a new NuGet config file that NuGet will use into a temp file
274282
configFile, err = os.CreateTemp(configDirPath, configFilePattern)
275283
if errorutils.CheckError(err) != nil {
@@ -283,12 +291,12 @@ func InitNewConfig(configDirPath, repoName string, server *config.ServerDetails,
283291
// We would prefer to write the NuGet configuration using the `nuget add source` command,
284292
// but the NuGet configuration utility doesn't currently allow setting protocolVersion.
285293
// Until that is supported, the templated method must be used.
286-
err = addSourceToNugetTemplate(configFile, server, useNugetV2, repoName)
294+
err = addSourceToNugetTemplate(configFile, server, useNugetV2, repoName, allowInsecureConnections)
287295
return
288296
}
289297

290298
// Adds a source to the nuget config template
291-
func addSourceToNugetTemplate(configFile *os.File, server *config.ServerDetails, useNugetV2 bool, repoName string) error {
299+
func addSourceToNugetTemplate(configFile *os.File, server *config.ServerDetails, useNugetV2 bool, repoName string, allowInsecureConnections bool) error {
292300
sourceUrl, user, password, err := GetSourceDetails(server, repoName, useNugetV2)
293301
if err != nil {
294302
return err
@@ -301,7 +309,7 @@ func addSourceToNugetTemplate(configFile *os.File, server *config.ServerDetails,
301309
}
302310

303311
// Format the templates
304-
_, err = fmt.Fprintf(configFile, dotnet.ConfigFileFormat, sourceUrl, protoVer, user, password)
312+
_, err = fmt.Fprintf(configFile, dotnet.ConfigFileFormat, sourceUrl, protoVer, allowInsecureConnections, user, password)
305313
return err
306314
}
307315

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, true)
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="true"/>
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) {

common/spec/specfiles.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package spec
22

33
import (
44
"encoding/json"
5-
65
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
76
"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
87
clientutils "github.com/jfrog/jfrog-client-go/utils"
@@ -39,6 +38,23 @@ func CreateSpecFromFile(specFilePath string, specVars map[string]string) (spec *
3938
return
4039
}
4140

41+
func CreateSpecFromBuildNameAndNumber(buildName, buildNumber string) (*SpecFiles, error) {
42+
if buildName == "" || buildNumber == "" {
43+
return nil, errorutils.CheckErrorf("build name and build number must be provided")
44+
}
45+
46+
buildString := buildName + "/" + buildNumber
47+
specFile := &SpecFiles{
48+
Files: []File{
49+
{
50+
Build: buildString,
51+
},
52+
},
53+
}
54+
55+
return specFile, nil
56+
}
57+
4258
type File struct {
4359
Aql utils.Aql
4460
PathMapping utils.PathMapping

common/spec/specfiles_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package spec
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"testing"
6+
)
7+
8+
func TestCreateSpecFromBuildNameAndNumber(t *testing.T) {
9+
t.Run("Valid Inputs", func(t *testing.T) {
10+
spec, err := CreateSpecFromBuildNameAndNumber("Common-builds", "1.2.0")
11+
12+
assert.NoError(t, err)
13+
assert.NotNil(t, spec)
14+
assert.Equal(t, "Common-builds/1.2.0", spec.Files[0].Build)
15+
})
16+
17+
t.Run("Missing Build Name", func(t *testing.T) {
18+
spec, err := CreateSpecFromBuildNameAndNumber("", "1.2.0")
19+
20+
assert.Error(t, err)
21+
assert.Nil(t, spec)
22+
assert.EqualError(t, err, "build name and build number must be provided")
23+
})
24+
25+
t.Run("Missing Build Number", func(t *testing.T) {
26+
spec, err := CreateSpecFromBuildNameAndNumber("Common-builds", "")
27+
28+
assert.Error(t, err)
29+
assert.Nil(t, spec)
30+
assert.EqualError(t, err, "build name and build number must be provided")
31+
})
32+
33+
t.Run("Empty Build Name and Build Number", func(t *testing.T) {
34+
spec, err := CreateSpecFromBuildNameAndNumber("", "")
35+
36+
assert.Error(t, err)
37+
assert.Nil(t, spec)
38+
assert.EqualError(t, err, "build name and build number must be provided")
39+
})
40+
}

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ require (
1212
github.com/google/uuid v1.6.0
1313
github.com/gookit/color v1.5.4
1414
github.com/jedib0t/go-pretty/v6 v6.6.1
15-
github.com/jfrog/build-info-go v1.10.5
15+
github.com/jfrog/build-info-go v1.10.6
1616
github.com/jfrog/gofrog v1.7.6
17-
github.com/jfrog/jfrog-client-go v1.48.0
17+
github.com/jfrog/jfrog-client-go v1.48.1
1818
github.com/magiconair/properties v1.8.7
1919
github.com/manifoldco/promptui v0.9.0
2020
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
@@ -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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ 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.10.6 h1:zH1ZhXlVfi5DlFyunygHjrdOcnv5qxfeLqmsfD4+lc4=
93+
github.com/jfrog/build-info-go v1.10.6/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=
96-
github.com/jfrog/jfrog-client-go v1.48.0 h1:hx5B7+Wnobmzq4aFVZtALtbEVDFcjpn0Wb4q2m6H4KU=
97-
github.com/jfrog/jfrog-client-go v1.48.0/go.mod h1:1a7bmQHkRmPEza9wva2+WVrYzrGbosrMymq57kyG5gU=
96+
github.com/jfrog/jfrog-client-go v1.48.1 h1:R6x6gazy0F196XXDhDdRAxmNplSJ5SrJfEmmNBgks/8=
97+
github.com/jfrog/jfrog-client-go v1.48.1/go.mod h1:1a7bmQHkRmPEza9wva2+WVrYzrGbosrMymq57kyG5gU=
9898
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
9999
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
100100
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=

0 commit comments

Comments
 (0)