35
35
import java .util .stream .Stream ;
36
36
37
37
import static org .jfrog .build .api .util .FileChecksumCalculator .*;
38
+ import static org .jfrog .build .extractor .clientConfiguration .ArtifactoryClientConfiguration .DEFAULT_NUGET_ALLOW_INSECURE_CONNECTIONS ;
38
39
import static org .jfrog .build .extractor .clientConfiguration .ArtifactoryClientConfiguration .DEFAULT_NUGET_PROTOCOL ;
39
40
import static org .jfrog .build .extractor .packageManager .PackageManagerUtils .createArtifactoryClientConfiguration ;
40
41
@@ -47,7 +48,7 @@ public class NugetRun extends PackageManagerExtractor {
47
48
private static final String CONFIG_FILE_FORMAT = "<?xml version=\" 1.0\" encoding=\" utf-8\" ?>\n " +
48
49
"<configuration>\n " +
49
50
"\t <packageSources>\n " +
50
- "\t \t <add key=\" JFrogJenkins\" value=\" %s\" protocolVersion=\" %s\" />\n " +
51
+ "\t \t <add key=\" JFrogJenkins\" value=\" %s\" protocolVersion=\" %s\" allowInsecureConnections= \" %s \" />\n " +
51
52
"\t </packageSources>\n " +
52
53
"\t <packageSourceCredentials>\n " +
53
54
"\t \t <JFrogJenkins>\n " +
@@ -75,6 +76,7 @@ public class NugetRun extends PackageManagerExtractor {
75
76
private String apiProtocol ;
76
77
private String module ;
77
78
private String nugetCmdArgs ;
79
+ private boolean allowInsecureConnections ;
78
80
private List <String > dependenciesSources ;
79
81
private List <Module > modulesList = new ArrayList <>();
80
82
@@ -91,10 +93,11 @@ public class NugetRun extends PackageManagerExtractor {
91
93
* @param module - NuGet module
92
94
* @param username - JFrog platform username.
93
95
* @param password - JFrog platform password.
96
+ * @param allowInsecureConnections - Allow insecure package sources connection, should be used only for developing.
94
97
* @param apiProtocol - A string indicates which NuGet protocol should be used (V2/V3).
95
98
*/
96
99
97
- public NugetRun (ArtifactoryManagerBuilder artifactoryManagerBuilder , String resolutionRepo , boolean useDotnetCli , String nugetCmdArgs , Log logger , Path path , Map <String , String > env , String module , String username , String password , String apiProtocol ) {
100
+ public NugetRun (ArtifactoryManagerBuilder artifactoryManagerBuilder , String resolutionRepo , boolean useDotnetCli , String nugetCmdArgs , Log logger , Path path , Map <String , String > env , String module , String username , String password , String apiProtocol , Boolean allowInsecureConnections ) {
98
101
this .artifactoryManagerBuilder = artifactoryManagerBuilder ;
99
102
this .toolchainDriver = useDotnetCli ? new DotnetDriver (env , path , logger ) : new NugetDriver (env , path , logger );
100
103
this .workingDir = Files .isDirectory (path ) ? path : path .toAbsolutePath ().getParent ();
@@ -106,6 +109,7 @@ public NugetRun(ArtifactoryManagerBuilder artifactoryManagerBuilder, String reso
106
109
this .password = password ;
107
110
this .apiProtocol = StringUtils .isBlank (apiProtocol ) ? DEFAULT_NUGET_PROTOCOL : apiProtocol ;
108
111
this .module = module ;
112
+ this .allowInsecureConnections = allowInsecureConnections == null ? DEFAULT_NUGET_ALLOW_INSECURE_CONNECTIONS : allowInsecureConnections ;
109
113
}
110
114
111
115
private static String removeQuotes (String str ) {
@@ -160,7 +164,8 @@ public static void main(String[] ignored) {
160
164
handler .getModule (),
161
165
clientConfiguration .resolver .getUsername (),
162
166
clientConfiguration .resolver .getPassword (),
163
- clientConfiguration .dotnetHandler .apiProtocol ());
167
+ clientConfiguration .dotnetHandler .apiProtocol (),
168
+ clientConfiguration .getNuGetAllowInsecureConnections ());
164
169
nugetRun .executeAndSaveBuildInfo (clientConfiguration );
165
170
} catch (RuntimeException e ) {
166
171
ExceptionUtils .printRootCauseStackTrace (e , System .out );
@@ -208,7 +213,7 @@ private File prepareConfig(ArtifactoryManager artifactoryManager) throws Excepti
208
213
if (!nugetCmdArgs .contains (toolchainDriver .getFlagSyntax (ToolchainDriverBase .CONFIG_FILE_FLAG )) && !nugetCmdArgs .contains (toolchainDriver .getFlagSyntax (ToolchainDriverBase .SOURCE_FLAG ))) {
209
214
configFile = File .createTempFile (NUGET_CONFIG_FILE_PREFIX , null );
210
215
configFile .deleteOnExit ();
211
- addSourceToConfigFile (configFile .getAbsolutePath (), artifactoryManager , resolutionRepo , username , password , apiProtocol );
216
+ addSourceToConfigFile (configFile .getAbsolutePath (), artifactoryManager , resolutionRepo , username , password , apiProtocol , allowInsecureConnections );
212
217
}
213
218
return configFile ;
214
219
}
@@ -217,10 +222,10 @@ private File prepareConfig(ArtifactoryManager artifactoryManager) throws Excepti
217
222
* We will write a temporary NuGet configuration using a string formater in order to support NuGet v3 protocol.
218
223
* Currently the NuGet configuration utility doesn't allow setting protocolVersion.
219
224
*/
220
- private void addSourceToConfigFile (String configPath , ArtifactoryManager client , String repo , String username , String password , String apiProtocol ) throws Exception {
225
+ private void addSourceToConfigFile (String configPath , ArtifactoryManager client , String repo , String username , String password , String apiProtocol , boolean allowInsecureConnections ) throws Exception {
221
226
String sourceUrl = toolchainDriver .buildNugetSourceUrl (client , repo , apiProtocol );
222
227
String protocolVersion = apiProtocol .substring (apiProtocol .length () - 1 );
223
- String configFileText = String .format (CONFIG_FILE_FORMAT , sourceUrl , protocolVersion , username , password );
228
+ String configFileText = String .format (CONFIG_FILE_FORMAT , sourceUrl , protocolVersion , Boolean . toString ( allowInsecureConnections ), username , password );
224
229
try (PrintWriter out = new PrintWriter (configPath )) {
225
230
out .println (configFileText );
226
231
}
0 commit comments