@@ -30,14 +30,16 @@ The initial error is:
3030)
3131
3232type 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+ // Used mostly for testings, allow insecured conntions sources.
40+ allowInsecureConnections bool
41+ buildConfiguration * commonBuild.BuildConfiguration
42+ serverDetails * config.ServerDetails
4143}
4244
4345func (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+
7380func (dc * DotnetCommand ) SetArgAndFlags (argAndFlags []string ) * DotnetCommand {
7481 dc .argAndFlags = argAndFlags
7582 return dc
@@ -219,7 +226,7 @@ func (dc *DotnetCommand) prepareConfigFileIfNeeded() (cleanup func() error, err
219226 return fileutils .RemoveTempDir (tempDirPath )
220227 }
221228
222- configFile , err := InitNewConfig (tempDirPath , dc .repoName , dc .serverDetails , dc .useNugetV2 )
229+ configFile , err := InitNewConfig (tempDirPath , dc .repoName , dc .serverDetails , dc .useNugetV2 , dc . allowInsecureConnections )
223230 if err == nil {
224231 dc .argAndFlags = append (dc .argAndFlags , dc .GetToolchain ().GetTypeFlagPrefix ()+ "configfile" , configFile .Name ())
225232 }
@@ -246,7 +253,7 @@ func getFlagValueIfExists(cmdFlag string, argAndFlags []string) (string, error)
246253}
247254
248255// InitNewConfig is used when neither of the flags were provided, and we need to init our own config.
249- func InitNewConfig (configDirPath , repoName string , server * config.ServerDetails , useNugetV2 bool ) (configFile * os.File , err error ) {
256+ func InitNewConfig (configDirPath , repoName string , server * config.ServerDetails , useNugetV2 , allowInsecureConnections bool ) (configFile * os.File , err error ) {
250257 // Initializing a new NuGet config file that NuGet will use into a temp file
251258 configFile , err = os .CreateTemp (configDirPath , configFilePattern )
252259 if errorutils .CheckError (err ) != nil {
@@ -260,12 +267,12 @@ func InitNewConfig(configDirPath, repoName string, server *config.ServerDetails,
260267 // We would prefer to write the NuGet configuration using the `nuget add source` command,
261268 // but the NuGet configuration utility doesn't currently allow setting protocolVersion.
262269 // Until that is supported, the templated method must be used.
263- err = addSourceToNugetTemplate (configFile , server , useNugetV2 , repoName )
270+ err = addSourceToNugetTemplate (configFile , server , useNugetV2 , repoName , allowInsecureConnections )
264271 return
265272}
266273
267274// Adds a source to the nuget config template
268- func addSourceToNugetTemplate (configFile * os.File , server * config.ServerDetails , useNugetV2 bool , repoName string ) error {
275+ func addSourceToNugetTemplate (configFile * os.File , server * config.ServerDetails , useNugetV2 bool , repoName string , allowInsecureConnections bool ) error {
269276 sourceUrl , user , password , err := getSourceDetails (server , repoName , useNugetV2 )
270277 if err != nil {
271278 return err
@@ -278,7 +285,7 @@ func addSourceToNugetTemplate(configFile *os.File, server *config.ServerDetails,
278285 }
279286
280287 // Format the templates
281- _ , err = fmt .Fprintf (configFile , dotnet .ConfigFileFormat , sourceUrl , protoVer , user , password )
288+ _ , err = fmt .Fprintf (configFile , dotnet .ConfigFileFormat , sourceUrl , protoVer , allowInsecureConnections , user , password )
282289 return err
283290}
284291
0 commit comments