diff --git a/api/src/main/java/com/redhat/insights/config/EnvAndSysPropsInsightsConfiguration.java b/api/src/main/java/com/redhat/insights/config/EnvAndSysPropsInsightsConfiguration.java index 5689d243..34ee8105 100644 --- a/api/src/main/java/com/redhat/insights/config/EnvAndSysPropsInsightsConfiguration.java +++ b/api/src/main/java/com/redhat/insights/config/EnvAndSysPropsInsightsConfiguration.java @@ -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; @@ -24,6 +25,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"; @@ -116,7 +118,13 @@ public Optional 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))); } diff --git a/api/src/main/java/com/redhat/insights/http/BackoffWrapper.java b/api/src/main/java/com/redhat/insights/http/BackoffWrapper.java index 7bcc8cbd..89152ada 100644 --- a/api/src/main/java/com/redhat/insights/http/BackoffWrapper.java +++ b/api/src/main/java/com/redhat/insights/http/BackoffWrapper.java @@ -21,6 +21,12 @@ public interface Action { void run() throws Throwable; } + public static class FatalBackoffException extends RuntimeException { + public FatalBackoffException(String message, Throwable cause) { + super(message, cause); + } + } + private final InsightsLogger logger; private final long initialDelay; private final double factor; @@ -53,6 +59,13 @@ public int run() { action.run(); return count; } catch (Throwable err) { + if (err instanceof FatalBackoffException) { + InsightsException fatalErr = + new InsightsException( + ERROR_CLIENT_BACKOFF_RETRIES_FAILED, "Exponential backoff fatal error"); + fatalErr.addSuppressed(err); + throw fatalErr; + } if (retryFailure == null) { retryFailure = new InsightsException( diff --git a/api/src/test/java/com/redhat/insights/configuration/EnvVariableConfigurationTest.java b/api/src/test/java/com/redhat/insights/configuration/EnvVariableConfigurationTest.java index 16d63259..6eb48222 100644 --- a/api/src/test/java/com/redhat/insights/configuration/EnvVariableConfigurationTest.java +++ b/api/src/test/java/com/redhat/insights/configuration/EnvVariableConfigurationTest.java @@ -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.*; @@ -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(