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

feat: proxies can now be set using HTTPS_PROXY #261

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
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,7 @@
import static com.redhat.insights.InsightsErrorCode.ERROR_IDENTIFICATION_NOT_DEFINED;

import com.redhat.insights.InsightsException;
import java.net.URI;
import java.time.Duration;
import java.util.Optional;
import org.jspecify.annotations.NullMarked;
Expand All @@ -26,6 +27,7 @@ public class EnvAndSysPropsInsightsConfiguration extends DefaultInsightsConfigur
public static final String ENV_ARCHIVE_UPLOAD_DIR = "RHT_INSIGHTS_JAVA_ARCHIVE_UPLOAD_DIR";
public static final String ENV_PROXY_HOST = "RHT_INSIGHTS_JAVA_PROXY_HOST";
public static final String ENV_PROXY_PORT = "RHT_INSIGHTS_JAVA_PROXY_PORT";
public static final String ENV_HTTPS_PROXY = "HTTPS_PROXY";
public static final String ENV_OPT_OUT = "RHT_INSIGHTS_JAVA_OPT_OUT";
public static final String ENV_CONNECT_PERIOD = "RHT_INSIGHTS_JAVA_CONNECT_PERIOD";
public static final String ENV_UPDATE_PERIOD = "RHT_INSIGHTS_JAVA_UPDATE_PERIOD";
Expand Down Expand Up @@ -118,7 +120,13 @@ public Optional<ProxyConfiguration> getProxyConfiguration() {
String host = lookup(ENV_PROXY_HOST);
String port = lookup(ENV_PROXY_PORT);
if (host == null || port == null) {
return Optional.empty();
String httpsProxy = lookup(ENV_HTTPS_PROXY);
if (httpsProxy == null) {
return Optional.empty();
}
URI proxyUri = URI.create(httpsProxy);
host = proxyUri.getHost();
port = Integer.toString(proxyUri.getPort());
}
return Optional.of(new ProxyConfiguration(host, Integer.parseUnsignedInt(port)));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) Red Hat 2023 */
/* Copyright (C) Red Hat 2023-2024 */
package com.redhat.insights.configuration;

import static com.redhat.insights.config.EnvAndSysPropsInsightsConfiguration.*;
Expand Down Expand Up @@ -98,6 +98,33 @@ void testGetProxyConfiguration() {
"Configuration does not contain value passed through environment variable.");
}

@Test
void testGetProxyConfigurationWithUnusedEnv() {
environmentVariables.set(ENV_HTTPS_PROXY, "https://env-https-proxy-host:54321");
assertEquals(
"env-proxy-host",
config.getProxyConfiguration().get().getHost(),
"Configuration does not contain value passed through environment variable.");
assertEquals(
12345,
config.getProxyConfiguration().get().getPort(),
"Configuration does not contain value passed through environment variable.");
}

@Test
void testGetProxyConfigurationAlternative() {
environmentVariables.remove(ENV_PROXY_HOST).remove(ENV_PROXY_PORT);
environmentVariables.set(ENV_HTTPS_PROXY, "https://env-https-proxy-host:54321");
assertEquals(
"env-https-proxy-host",
config.getProxyConfiguration().get().getHost(),
"Configuration does not contain value passed through environment variable.");
assertEquals(
54321,
config.getProxyConfiguration().get().getPort(),
"Configuration does not contain value passed through environment variable.");
}

@Test
void testIsOptingOut() {
assertEquals(
Expand Down