Skip to content

Commit

Permalink
Merge branch 'dev' into feature/RTDEV-50692
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalbe4 authored Dec 11, 2024
2 parents 3e12a85 + 60f1f74 commit a49f772
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 31 deletions.
36 changes: 22 additions & 14 deletions artifactory/commands/dotnet/dotnetcommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import (
)

const (
SourceName = "JFrogArtifactory"
// SourceName should match the one in the config file template.
SourceName = "JFrogCli"
configFilePattern = "jfrog.cli.nuget."

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

type DotnetCommand struct {
toolchainType dotnet.ToolchainType
subCommand string
argAndFlags []string
repoName string
solutionPath string
useNugetV2 bool
buildConfiguration *commonBuild.BuildConfiguration
serverDetails *config.ServerDetails
toolchainType dotnet.ToolchainType
subCommand string
argAndFlags []string
repoName string
solutionPath string
useNugetV2 bool
// By default, package sources are required to use HTTPS. This option allows sources to use HTTP.
allowInsecureConnections bool
buildConfiguration *commonBuild.BuildConfiguration
serverDetails *config.ServerDetails
}

func (dc *DotnetCommand) SetServerDetails(serverDetails *config.ServerDetails) *DotnetCommand {
Expand Down Expand Up @@ -70,6 +73,11 @@ func (dc *DotnetCommand) SetUseNugetV2(useNugetV2 bool) *DotnetCommand {
return dc
}

func (dc *DotnetCommand) SetAllowInsecureConnections(allowInsecureConnections bool) *DotnetCommand {
dc.allowInsecureConnections = allowInsecureConnections
return dc
}

func (dc *DotnetCommand) SetArgAndFlags(argAndFlags []string) *DotnetCommand {
dc.argAndFlags = argAndFlags
return dc
Expand Down Expand Up @@ -242,7 +250,7 @@ func (dc *DotnetCommand) prepareConfigFileIfNeeded() (cleanup func() error, err
return fileutils.RemoveTempDir(tempDirPath)
}

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

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

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

// Format the templates
_, err = fmt.Fprintf(configFile, dotnet.ConfigFileFormat, sourceUrl, protoVer, user, password)
_, err = fmt.Fprintf(configFile, dotnet.ConfigFileFormat, sourceUrl, protoVer, allowInsecureConnections, user, password)
return err
}

Expand Down
19 changes: 10 additions & 9 deletions artifactory/commands/dotnet/dotnetcommand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestInitNewConfig(t *testing.T) {
User: "user",
Password: "pass",
}
configFile, err := InitNewConfig(tmpDir, repoName, server, false)
configFile, err := InitNewConfig(tmpDir, repoName, server, false, true)
assert.NoError(t, err)
f, err := os.Open(configFile.Name())
assert.NoError(t, err)
Expand All @@ -87,7 +87,7 @@ func TestInitNewConfig(t *testing.T) {
assert.Equal(t, `<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="JFrogCli" value="https://server.com/artifactory/api/nuget/v3/test-repo" protocolVersion="3" />
<add key="JFrogCli" value="https://server.com/artifactory/api/nuget/v3/test-repo" protocolVersion="3" allowInsecureConnections="true"/>
</packageSources>
<packageSourceCredentials>
<JFrogCli>
Expand All @@ -98,7 +98,7 @@ func TestInitNewConfig(t *testing.T) {
</configuration>`, string(buf[:n]))
server.Password = ""
server.AccessToken = "abc123"
configFile, err = InitNewConfig(tmpDir, repoName, server, true)
configFile, err = InitNewConfig(tmpDir, repoName, server, true, true)
assert.NoError(t, err)
updatedConfigFile, err := os.Open(configFile.Name())
assert.NoError(t, err)
Expand All @@ -111,7 +111,7 @@ func TestInitNewConfig(t *testing.T) {
assert.Equal(t, `<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="JFrogCli" value="https://server.com/artifactory/api/nuget/test-repo" protocolVersion="2" />
<add key="JFrogCli" value="https://server.com/artifactory/api/nuget/test-repo" protocolVersion="2" allowInsecureConnections="true"/>
</packageSources>
<packageSourceCredentials>
<JFrogCli>
Expand Down Expand Up @@ -164,11 +164,12 @@ func testPrepareDotnetBuildInfoModule(t *testing.T, subCommand string, flags []s
}()
module := createNewDotnetModule(t, tmpDir)
cmd := DotnetCommand{
toolchainType: dotnet.DotnetCore,
subCommand: subCommand,
argAndFlags: flags,
buildConfiguration: buildUtils.NewBuildConfiguration("", "", "mod", ""),
serverDetails: &config.ServerDetails{ArtifactoryUrl: "https://my-instance.jfrog.io"},
toolchainType: dotnet.DotnetCore,
subCommand: subCommand,
argAndFlags: flags,
buildConfiguration: buildUtils.NewBuildConfiguration("", "", "mod", ""),
serverDetails: &config.ServerDetails{ArtifactoryUrl: "https://my-instance.jfrog.io"},
allowInsecureConnections: true,
}
callbackFunc, err := cmd.prepareDotnetBuildInfoModule(module)
if !assert.NoError(t, err) {
Expand Down
18 changes: 17 additions & 1 deletion common/spec/specfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package spec

import (
"encoding/json"

"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
clientutils "github.com/jfrog/jfrog-client-go/utils"
Expand Down Expand Up @@ -39,6 +38,23 @@ func CreateSpecFromFile(specFilePath string, specVars map[string]string) (spec *
return
}

func CreateSpecFromBuildNameAndNumber(buildName, buildNumber string) (*SpecFiles, error) {
if buildName == "" || buildNumber == "" {
return nil, errorutils.CheckErrorf("build name and build number must be provided")
}

buildString := buildName + "/" + buildNumber
specFile := &SpecFiles{
Files: []File{
{
Build: buildString,
},
},
}

return specFile, nil
}

type File struct {
Aql utils.Aql
PathMapping utils.PathMapping
Expand Down
40 changes: 40 additions & 0 deletions common/spec/specfiles_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package spec

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestCreateSpecFromBuildNameAndNumber(t *testing.T) {
t.Run("Valid Inputs", func(t *testing.T) {
spec, err := CreateSpecFromBuildNameAndNumber("Common-builds", "1.2.0")

assert.NoError(t, err)
assert.NotNil(t, spec)
assert.Equal(t, "Common-builds/1.2.0", spec.Files[0].Build)
})

t.Run("Missing Build Name", func(t *testing.T) {
spec, err := CreateSpecFromBuildNameAndNumber("", "1.2.0")

assert.Error(t, err)
assert.Nil(t, spec)
assert.EqualError(t, err, "build name and build number must be provided")
})

t.Run("Missing Build Number", func(t *testing.T) {
spec, err := CreateSpecFromBuildNameAndNumber("Common-builds", "")

assert.Error(t, err)
assert.Nil(t, spec)
assert.EqualError(t, err, "build name and build number must be provided")
})

t.Run("Empty Build Name and Build Number", func(t *testing.T) {
spec, err := CreateSpecFromBuildNameAndNumber("", "")

assert.Error(t, err)
assert.Nil(t, spec)
assert.EqualError(t, err, "build name and build number must be provided")
})
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ require (
github.com/google/uuid v1.6.0
github.com/gookit/color v1.5.4
github.com/jedib0t/go-pretty/v6 v6.6.1
github.com/jfrog/build-info-go v1.10.5
github.com/jfrog/build-info-go v1.10.6
github.com/jfrog/gofrog v1.7.6
github.com/jfrog/jfrog-client-go v1.48.0
github.com/jfrog/jfrog-client-go v1.48.3
github.com/magiconair/properties v1.8.7
github.com/manifoldco/promptui v0.9.0
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
Expand Down Expand Up @@ -98,6 +98,6 @@ require (

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

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

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.3.3-0.20231223133729-ef57bd08cedc
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ 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/build-info-go v1.10.6 h1:zH1ZhXlVfi5DlFyunygHjrdOcnv5qxfeLqmsfD4+lc4=
github.com/jfrog/build-info-go v1.10.6/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
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-client-go v1.48.0 h1:hx5B7+Wnobmzq4aFVZtALtbEVDFcjpn0Wb4q2m6H4KU=
github.com/jfrog/jfrog-client-go v1.48.0/go.mod h1:1a7bmQHkRmPEza9wva2+WVrYzrGbosrMymq57kyG5gU=
github.com/jfrog/jfrog-client-go v1.48.3 h1:HJpKGul0f/S2i7Uf7K/GwS1EUGiirt1LWXL1lanKNhU=
github.com/jfrog/jfrog-client-go v1.48.3/go.mod h1:1a7bmQHkRmPEza9wva2+WVrYzrGbosrMymq57kyG5gU=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
Expand Down

0 comments on commit a49f772

Please sign in to comment.