use of hudson.ProxyConfiguration in project contrast-continuous-application-security-plugin by jenkinsci.
the class VulnerabilityTrendHelper method createSDK.
public static ContrastSDK createSDK(String username, String serviceKey, String apiKey, String teamServerUrl) {
ContrastSDK contrastSDK;
Jenkins jenkinsInstance = Jenkins.getInstance();
ProxyConfiguration proxyConfig = null;
if (jenkinsInstance != null) {
proxyConfig = jenkinsInstance.proxy;
}
URL url = null;
Proxy proxyToUse = Proxy.NO_PROXY;
try {
url = new URL(teamServerUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
}
if (proxyConfig != null && url != null) {
Proxy proxy = proxyConfig.createProxy(url.getHost());
if (proxy != null && proxy.type() == Proxy.Type.HTTP) {
proxyToUse = proxy;
}
}
contrastSDK = new ContrastSDK(username, serviceKey, apiKey, teamServerUrl, proxyToUse);
return contrastSDK;
}
use of hudson.ProxyConfiguration in project nodejs-plugin by jenkinsci.
the class NodeJSInstallerProxyTest method test_proxy_settings.
@Issue("JENKINS-29266")
@Test
public void test_proxy_settings() throws Exception {
r.getInstance().proxy = new ProxyConfiguration(host, port, username, password);
NodeJSInstaller installer = new NodeJSInstaller("test-id", "grunt", NodeJSInstaller.DEFAULT_NPM_PACKAGES_REFRESH_HOURS);
EnvVars env = new EnvVars();
Whitebox.invokeMethod(installer, "buildProxyEnvVars", env, log);
assertThat(env.keySet(), hasItems("HTTP_PROXY", "HTTPS_PROXY"));
assertThat(env.get("HTTP_PROXY"), is(expectedURL));
assertThat(env.get("HTTPS_PROXY"), is(expectedURL));
assertThat(env.keySet(), not(hasItem("NO_PROXY")));
}
use of hudson.ProxyConfiguration in project nodejs-plugin by jenkinsci.
the class NodeJSInstallerProxyTest method test_no_proxy_settings.
@Test
public void test_no_proxy_settings() throws Exception {
r.getInstance().proxy = new ProxyConfiguration(host, port, username, password, noProxy);
NodeJSInstaller installer = new NodeJSInstaller("test-id", "grunt", NodeJSInstaller.DEFAULT_NPM_PACKAGES_REFRESH_HOURS);
EnvVars env = new EnvVars();
Whitebox.invokeMethod(installer, "buildProxyEnvVars", env, log);
assertThat(env.keySet(), hasItems("HTTP_PROXY", "HTTPS_PROXY"));
assertThat(env.get("NO_PROXY"), is("*.npm.org,registry.npm.org"));
}
use of hudson.ProxyConfiguration in project jenkin-qtest-plugin by QASymphony.
the class HttpClientUtils method setHttpProxy.
private static void setHttpProxy(HttpClientBuilder httpClientBuilder, String hostUrl) {
ProxyConfiguration proxyConfig = Jenkins.getInstance().proxy;
if (proxyConfig != null) {
List<Pattern> proxyHostPatterns = proxyConfig.getNoProxyHostPatterns();
if (isUrlMatchWithNoProxyHost(hostUrl, proxyHostPatterns) == true) {
return;
}
HttpHost proxy = new HttpHost(proxyConfig.name, proxyConfig.port);
String username = proxyConfig.getUserName();
String password = proxyConfig.getPassword();
Credentials credentials;
if (username != null && StringUtils.isNotEmpty(username) == true) {
credentials = new UsernamePasswordCredentials(username, password);
} else {
credentials = new UsernamePasswordCredentials("", "");
}
AuthScope authScope = new AuthScope(proxyConfig.name, proxyConfig.port);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(authScope, credentials);
httpClientBuilder.setProxy(proxy).setDefaultCredentialsProvider(credsProvider).build();
}
}
use of hudson.ProxyConfiguration in project dependency-check-plugin by jenkinsci.
the class AbstractDependencyCheckBuilder method configureProxySettings.
void configureProxySettings(final Options options, final boolean isNvdProxyBypassed) {
final ProxyConfiguration proxy = Jenkins.getInstance() != null ? Jenkins.getInstance().proxy : null;
if (!isNvdProxyBypassed && proxy != null) {
if (!StringUtils.isBlank(proxy.name)) {
options.setProxyServer(proxy.name);
options.setProxyPort(proxy.port);
}
if (!StringUtils.isBlank(proxy.getUserName())) {
options.setProxyUsername(proxy.getUserName());
}
if (!StringUtils.isBlank(proxy.getPassword())) {
options.setProxyPassword(proxy.getPassword());
}
}
}
Aggregations