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

Support pipe and new line in the 'No proxy host' #106

Merged
merged 7 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ If you're using a JFrog platform that's situated behind an HTTP/S proxy, you sho
under `Manage Jenkins` > `Manage Plugins` > `Advanced`.

To exclude the JFrog platform from going through a configured proxy, provide your JFrog platform's host details in
the `No Proxy Host` section. This should be a list of comma-separated hosts.
the `No Proxy Host` section.
Notice that the JFrog CLI is typically downloaded from releases.jfrog.io. You may need to add that to your list as well.

## Jenkins Configuration as Code
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/io/jenkins/plugins/jfrog/CliEnvConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static void setupProxy(EnvVars env) {
env.put(HTTP_PROXY_ENV, proxyUrl);
env.put(HTTPS_PROXY_ENV, proxyUrl);
if (StringUtils.isNotBlank(proxyConfiguration.noProxy)) {
env.put(NO_PROXY, proxyConfiguration.noProxy);
env.put(NO_PROXY, noProxyExtractor(proxyConfiguration.noProxy));
}
}

Expand All @@ -79,4 +79,13 @@ private static void excludeProxyEnvFromPublishing(EnvVars env) {
String jfrogCliEnvExclude = env.getOrDefault(JFROG_CLI_ENV_EXCLUDE, JFROG_CLI_DEFAULT_EXCLUSIONS);
env.put(JFROG_CLI_ENV_EXCLUDE, String.join(";", jfrogCliEnvExclude, HTTP_PROXY_ENV, HTTPS_PROXY_ENV));
}

static String noProxyExtractor(String noProxyList) {
Nathan770 marked this conversation as resolved.
Show resolved Hide resolved
Nathan770 marked this conversation as resolved.
Show resolved Hide resolved
Nathan770 marked this conversation as resolved.
Show resolved Hide resolved
// Trim leading and trailing spaces
String noProxyListTrim = noProxyList.trim();
// Replace '|' with spaces and normalize whitespace
String noProxyListRemoveSpaceAndPipe = noProxyListTrim.replace("|", " ").replaceAll("\\s+", ";");
Nathan770 marked this conversation as resolved.
Show resolved Hide resolved
// Replace multiple spaces with a single semicolon
return noProxyListRemoveSpaceAndPipe.replaceAll(";+", ";").replaceAll(";$", "");
Nathan770 marked this conversation as resolved.
Show resolved Hide resolved
}
}
46 changes: 46 additions & 0 deletions src/test/java/io/jenkins/plugins/jfrog/NoProxyExtractorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.jenkins.plugins.jfrog;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Arrays;
import java.util.Collection;

import static io.jenkins.plugins.jfrog.CliEnvConfigurator.noProxyExtractor;
import static org.junit.Assert.assertEquals;

/**
* @author nathana
**/
@RunWith(Parameterized.class)
public class NoProxyExtractorTest {
Nathan770 marked this conversation as resolved.
Show resolved Hide resolved
private final String noProxyList;
private final String expectedResult;

public NoProxyExtractorTest(String noProxyList, String expectedResult) {
this.noProxyList = noProxyList;
Nathan770 marked this conversation as resolved.
Show resolved Hide resolved
this.expectedResult = expectedResult;
}

@Parameterized.Parameters
public static Collection<Object[]> dataProvider() {
return Arrays.asList(
Nathan770 marked this conversation as resolved.
Show resolved Hide resolved
new Object[]{"artifactory.jfrog.io", "artifactory.jfrog.io"},
new Object[]{"artifactory.jfrog.io \n artifactory1.jfrog.io ", "artifactory.jfrog.io;artifactory1.jfrog.io"},
new Object[]{" artifactory.jfrog.io \n \r artifactory1.jfrog.io;artifactory2.jfrog.io \n artifactory3.jfrog.io | artifactory4.jfrog.io \n artifactory5.jfrog.io ", "artifactory.jfrog.io;artifactory1.jfrog.io;artifactory2.jfrog.io;artifactory3.jfrog.io;artifactory4.jfrog.io;artifactory5.jfrog.io"},
new Object[]{"\r\n", ""},
new Object[]{";;;", ""},
new Object[]{"artifactory.jfrog.io;", "artifactory.jfrog.io"},
new Object[]{"artifactory.jfrog.io;artifactory1.jfrog.io", "artifactory.jfrog.io;artifactory1.jfrog.io"},
new Object[]{"artifactory.jfrog.io;artifactory1.jfrog.io;artifactory2.jfrog.io;artifactory3.jfrog.io", "artifactory.jfrog.io;artifactory1.jfrog.io;artifactory2.jfrog.io;artifactory3.jfrog.io"},
new Object[]{"artifactory.jfrog.io \nartifactory1.jfrog.io", "artifactory.jfrog.io;artifactory1.jfrog.io"},
new Object[]{"artifactory.jfrog.io \nartifactory1.jfrog.io\nartifactory2.jfrog.io \n artifactory3.jfrog.io", "artifactory.jfrog.io;artifactory1.jfrog.io;artifactory2.jfrog.io;artifactory3.jfrog.io"}
);
}

@Test
public void testNoProxyExtractor() {
assertEquals(expectedResult, noProxyExtractor(noProxyList));
}
}
Loading