Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honor system proxy settings #510

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add fallback to JVM system proxy values
if plugin proxy properties are not set
  • Loading branch information
Drew Hamilton committed Jun 1, 2021
commit 41b5c7d9e930d7f5b53b0ff84c9a6d90e9402676
Original file line number Diff line number Diff line change
@@ -178,7 +178,7 @@ private void deployArtifacts(ArtifactoryClientConfiguration accRoot, Map<String,
IncludeExcludePatterns patterns = new IncludeExcludePatterns(
publisher.getIncludePatterns(),
publisher.getExcludePatterns());
configureProxy(accRoot, artifactoryManager);
configureProxy(contextUrl, accRoot, artifactoryManager);
configConnectionTimeout(accRoot, artifactoryManager);
configRetriesParams(accRoot, artifactoryManager);
deployArtifacts(artifactoryTask.deployDetails, artifactoryManager, patterns, logPrefix, publisher.getMinChecksumDeploySizeKb());
@@ -201,18 +201,36 @@ private void deployArtifacts(ArtifactoryClientConfiguration accRoot, Map<String,
}
}

private void configureProxy(ArtifactoryClientConfiguration clientConf, ArtifactoryManager artifactoryManager) {
private void configureProxy(String contextUrl, ArtifactoryClientConfiguration clientConf, ArtifactoryManager artifactoryManager) {
ArtifactoryClientConfiguration.ProxyHandler proxy = clientConf.proxy;
String proxyHost = proxy.getHost();
if (StringUtils.isNotBlank(proxyHost) && proxy.getPort() != null) {
Integer proxyPort = proxy.getPort();

boolean isHttps = contextUrl.startsWith("http") && !contextUrl.startsWith("https");

// If no proxyHost is explicitly set, check for the JVM system proxyHost property:
if (StringUtils.isBlank(proxyHost)) {
String systemPropertyName = isHttps ? "https.proxyHost" : "http.proxyHost";
proxyHost = System.getProperty(systemPropertyName);
}
// If no proxyPort is explicitly set, check for the JVM system proxyPort property:
if (proxyPort == null) {
String systemPropertyName = isHttps ? "https.proxyPort" : "http.proxyPort";
String systemProxyPortValue = System.getProperty(systemPropertyName);
if (StringUtils.isNotBlank(systemProxyPortValue)) {
proxyPort = Integer.valueOf(systemProxyPortValue);
}
}

if (StringUtils.isNotBlank(proxyHost) && proxyPort != null) {
log.debug("Found proxy host '{}'", proxyHost);
String proxyUserName = proxy.getUsername();
if (StringUtils.isNotBlank(proxyUserName)) {
log.debug("Found proxy user name '{}'", proxyUserName);
artifactoryManager.setProxyConfiguration(proxyHost, proxy.getPort(), proxyUserName, proxy.getPassword());
artifactoryManager.setProxyConfiguration(proxyHost, proxyPort, proxyUserName, proxy.getPassword());
} else {
log.debug("No proxy user name and password found, using anonymous proxy");
artifactoryManager.setProxyConfiguration(proxyHost, proxy.getPort());
artifactoryManager.setProxyConfiguration(proxyHost, proxyPort);
}
}
}