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

Remove restriction on possible hosts for Java tracer URL #456

Merged
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import hudson.model.Node;
import hudson.model.TaskListener;
import hudson.util.Secret;
import jenkins.model.Jenkins;
import org.datadog.jenkins.plugins.datadog.DatadogUtilities;
import org.datadog.jenkins.plugins.datadog.apm.signature.SignatureVerifier;
import org.datadog.jenkins.plugins.datadog.clients.HttpClient;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -17,10 +22,6 @@
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import org.datadog.jenkins.plugins.datadog.DatadogUtilities;
import org.datadog.jenkins.plugins.datadog.apm.signature.SignatureVerifier;
import org.datadog.jenkins.plugins.datadog.clients.HttpClient;

final class JavaConfigurator implements TracerConfigurator {

Expand All @@ -33,9 +34,6 @@ final class JavaConfigurator implements TracerConfigurator {
private static final String TRACER_JAR_CACHE_TTL_ENV_VAR = "DATADOG_JENKINS_PLUGIN_TRACER_JAR_CACHE_TTL_MINUTES";
private static final int DEFAULT_TRACER_JAR_CACHE_TTL_MINUTES = 60 * 12;
private static final int TRACER_DOWNLOAD_TIMEOUT_MILLIS = 60_000;
private static final String DATADOG_DISTRIBUTION_HOST = "dtdg.co";
private static final String MAVEN_CENTRAL_HOST = "repo1.maven.org";
private static final String DATADOG_AGENT_MAVEN_DISTRIBUTION_PATH = "/maven2/com/datadoghq/dd-java-agent/";

private final HttpClient httpClient = new HttpClient(TRACER_DOWNLOAD_TIMEOUT_MILLIS);

Expand Down Expand Up @@ -129,27 +127,12 @@ private String getEnvVariable(DatadogTracerJobProperty<?> tracerConfig, String n
}

private String validateUserSuppliedTracerUrl(String distributionUrl) {
URL url;
try {
url = new URL(distributionUrl);
new URL(distributionUrl);
return distributionUrl;
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Error while parsing tracer distribution URL: " + distributionUrl, e);
}

String host = url.getHost();
if (DATADOG_DISTRIBUTION_HOST.equals(host)) {
return distributionUrl;
}

if (!MAVEN_CENTRAL_HOST.equals(host)) {
throw new IllegalArgumentException("Illegal tracer distribution host: " + host + " (" + distributionUrl + ")");
}

String path = url.getPath();
if (!path.startsWith(DATADOG_AGENT_MAVEN_DISTRIBUTION_PATH)) {
throw new IllegalArgumentException("Illegal tracer distribution path: " + path + " (" + distributionUrl + ")");
}
return distributionUrl;
}

private static Map<String, String> getEnvVariables(DatadogTracerJobProperty<?> tracerConfig,
Expand Down
Loading