Skip to content

Commit

Permalink
adding option to use jvm proxy settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jsboak committed May 31, 2024
1 parent 75ed501 commit 2a604a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/edu/ohio/ais/rundeck/HttpBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.util.EntityUtils;
import org.dom4j.DocumentHelper;
Expand All @@ -34,6 +35,7 @@
import org.yaml.snakeyaml.constructor.SafeConstructor;

import java.io.*;
import java.net.ProxySelector;
import java.security.GeneralSecurityException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
Expand Down Expand Up @@ -109,13 +111,18 @@ public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws Ce
httpClientBuilder.setSSLContext(sslContextBuilder.build());
}
if(options.containsKey("proxySettings") && Boolean.parseBoolean(options.get("proxySettings").toString())){
log.log(5, "using proxy IP: " + options.get("proxyIP").toString());
log.log(5, "using proxy Port: " + options.get("proxyPort").toString());
log.log(5, "proxy IP set in job: " + options.get("proxyIP").toString());

HttpHost proxy = new HttpHost(options.get("proxyIP").toString(), Integer.valueOf((String)options.get("proxyPort")), "http");
httpClientBuilder.setProxy(proxy);
}

if(options.get("useSystemProxySettings").equals("true")) {

httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault()));

}

return httpClientBuilder.build();
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/edu/ohio/ais/rundeck/HttpDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.dtolabs.rundeck.core.plugins.configuration.Describable;
import com.dtolabs.rundeck.core.plugins.configuration.Description;
import com.dtolabs.rundeck.core.plugins.configuration.PropertyScope;
import com.dtolabs.rundeck.core.plugins.configuration.StringRenderingConstants;
import com.dtolabs.rundeck.plugins.util.DescriptionBuilder;
import com.dtolabs.rundeck.plugins.util.PropertyBuilder;
Expand Down Expand Up @@ -165,6 +166,12 @@ public Description getDescription() {
.defaultValue("false")
.renderingOption(StringRenderingConstants.GROUP_NAME,"Print")
.build())
.property(PropertyBuilder.builder()
.booleanType("useSystemProxySettings")
.description("Choose whether to use proxy settings set on the JVM.")
.defaultValue("false")
.scope(PropertyScope.Project)
.build())
.build();
}
}

0 comments on commit 2a604a5

Please sign in to comment.