Search in sources :

Example 6 with ProxyConfiguration

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);
}
Also used : Proxy(java.net.Proxy) ProxyConfiguration(hudson.ProxyConfiguration) KeenProject(io.keen.client.java.KeenProject)

Example 7 with ProxyConfiguration

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");
}
Also used : ProxyConfiguration(hudson.ProxyConfiguration) EnvVars(hudson.EnvVars) Test(org.junit.Test)

Example 8 with ProxyConfiguration

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");
}
Also used : ProxyConfiguration(hudson.ProxyConfiguration) EnvVars(hudson.EnvVars) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 9 with ProxyConfiguration

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;
}
Also used : Jenkins(jenkins.model.Jenkins) ContrastSDK(com.contrastsecurity.sdk.ContrastSDK) Proxy(java.net.Proxy) MalformedURLException(java.net.MalformedURLException) ProxyConfiguration(hudson.ProxyConfiguration) URL(java.net.URL)

Example 10 with ProxyConfiguration

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();
    }
}
Also used : Pattern(java.util.regex.Pattern) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) ProxyConfiguration(hudson.ProxyConfiguration) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Aggregations

ProxyConfiguration (hudson.ProxyConfiguration)16 Test (org.junit.Test)8 Proxy (java.net.Proxy)5 URL (java.net.URL)5 ConfiguredWithCode (io.jenkins.plugins.casc.misc.ConfiguredWithCode)4 EnvVars (hudson.EnvVars)2 ConfigurationContext (io.jenkins.plugins.casc.ConfigurationContext)2 Configurator (io.jenkins.plugins.casc.Configurator)2 ConfiguratorRegistry (io.jenkins.plugins.casc.ConfiguratorRegistry)2 Env (io.jenkins.plugins.casc.misc.Env)2 CNode (io.jenkins.plugins.casc.model.CNode)2 Mapping (io.jenkins.plugins.casc.model.Mapping)2 HttpURLConnection (java.net.HttpURLConnection)2 MalformedURLException (java.net.MalformedURLException)2 HttpHost (org.apache.http.HttpHost)2 Issue (org.jvnet.hudson.test.Issue)2 ContrastSDK (com.contrastsecurity.sdk.ContrastSDK)1 ServiceException (io.jenkins.blueocean.commons.ServiceException)1 ConfiguredWithReadme (io.jenkins.plugins.casc.misc.ConfiguredWithReadme)1 KeenProject (io.keen.client.java.KeenProject)1