use of hudson.ProxyConfiguration in project blueocean-plugin by jenkinsci.
the class KeenAnalyticsImpl method doTrack.
@Override
protected void doTrack(String name, Map<String, Object> allProps) {
// Always set the proxy in case its configuration has changed after startup
ProxyConfiguration proxyConfig = Jenkins.get().proxy;
Proxy proxy = proxyConfig == null ? null : proxyConfig.createProxy(null);
CLIENT.setProxy(proxy);
// Ensure that we are using the right project info
KeenProject project = KeenConfiguration.get().project();
CLIENT.setDefaultProject(project);
// Send the event
CLIENT.addEventAsync(name, allProps);
}
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);
Assertions.assertThat(env.keySet()).contains("HTTP_PROXY", "HTTPS_PROXY");
Assertions.assertThat(env.get("NO_PROXY")).isEqualTo("*.npm.org,registry.npm.org");
}
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);
Assertions.assertThat(env.keySet()).contains("HTTP_PROXY", "HTTPS_PROXY");
Assertions.assertThat(env.get("HTTP_PROXY")).isEqualTo(expectedURL);
Assertions.assertThat(env.get("HTTPS_PROXY")).isEqualTo(expectedURL);
Assertions.assertThat(env.keySet()).doesNotContain("NO_PROXY");
}
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 jenkin-qtest-plugin by QASymphony.
the class HttpClientUtils method setHttpProxy.
private static void setHttpProxy(HttpClientBuilder httpClientBuilder, String hostUrl) {
ProxyConfiguration proxyConfig = Jenkins.getInstance().proxy;
LOG.log(Level.INFO, "-- Proxy info: " + ReflectionToStringBuilder.toString(proxyConfig));
if (proxyConfig != null) {
List<Pattern> proxyHostPatterns = proxyConfig.getNoProxyHostPatterns();
LOG.log(Level.INFO, "-- No proxy host info: " + Arrays.toString(proxyHostPatterns.toArray()));
if (isUrlMatchWithNoProxyHost(hostUrl, proxyHostPatterns)) {
LOG.log(Level.INFO, "-- No proxy host has url: " + hostUrl);
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.useSystemProperties();
httpClientBuilder.setProxy(proxy).setDefaultCredentialsProvider(credsProvider).build();
}
}
Aggregations