Skip to content

Commit 12eccb1

Browse files
authored
Merge pull request #50709 from ppalaga/i50512
Introduce global HTTP proxy settings configuration
2 parents 2b84d82 + 3885a85 commit 12eccb1

File tree

40 files changed

+1015
-58
lines changed

40 files changed

+1015
-58
lines changed

bom/application/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,17 @@
832832
<version>${project.version}</version>
833833
</dependency>
834834

835+
<dependency>
836+
<groupId>io.quarkus</groupId>
837+
<artifactId>quarkus-proxy-registry</artifactId>
838+
<version>${project.version}</version>
839+
</dependency>
840+
<dependency>
841+
<groupId>io.quarkus</groupId>
842+
<artifactId>quarkus-proxy-registry-deployment</artifactId>
843+
<version>${project.version}</version>
844+
</dependency>
845+
835846
<!-- Quarkus extensions -->
836847

837848
<dependency>

devtools/bom-descriptor-json/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,19 @@
20392039
</exclusion>
20402040
</exclusions>
20412041
</dependency>
2042+
<dependency>
2043+
<groupId>io.quarkus</groupId>
2044+
<artifactId>quarkus-proxy-registry</artifactId>
2045+
<version>${project.version}</version>
2046+
<type>pom</type>
2047+
<scope>test</scope>
2048+
<exclusions>
2049+
<exclusion>
2050+
<groupId>*</groupId>
2051+
<artifactId>*</artifactId>
2052+
</exclusion>
2053+
</exclusions>
2054+
</dependency>
20422055
<dependency>
20432056
<groupId>io.quarkus</groupId>
20442057
<artifactId>quarkus-quartz</artifactId>

docs/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,6 +2003,19 @@
20032003
</exclusion>
20042004
</exclusions>
20052005
</dependency>
2006+
<dependency>
2007+
<groupId>io.quarkus</groupId>
2008+
<artifactId>quarkus-proxy-registry-deployment</artifactId>
2009+
<version>${project.version}</version>
2010+
<type>pom</type>
2011+
<scope>test</scope>
2012+
<exclusions>
2013+
<exclusion>
2014+
<groupId>*</groupId>
2015+
<artifactId>*</artifactId>
2016+
</exclusion>
2017+
</exclusions>
2018+
</dependency>
20062019
<dependency>
20072020
<groupId>io.quarkus</groupId>
20082021
<artifactId>quarkus-quartz-deployment</artifactId>

extensions/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<modules>
1717
<module>virtual-threads</module>
1818
<module>tls-registry</module>
19+
<module>proxy-registry</module>
1920

2021
<!-- Plumbing -->
2122
<module>arc</module>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>quarkus-proxy-registry-parent</artifactId>
7+
<groupId>io.quarkus</groupId>
8+
<version>999-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>quarkus-proxy-registry-deployment</artifactId>
13+
<name>Quarkus - Proxy Registry - Deployment</name>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>io.quarkus</groupId>
18+
<artifactId>quarkus-arc-deployment</artifactId>
19+
</dependency>
20+
<dependency>
21+
<groupId>io.quarkus</groupId>
22+
<artifactId>quarkus-proxy-registry</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>io.quarkus</groupId>
26+
<artifactId>quarkus-core-deployment</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>io.quarkus</groupId>
30+
<artifactId>quarkus-credentials-deployment</artifactId>
31+
</dependency>
32+
</dependencies>
33+
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<artifactId>maven-compiler-plugin</artifactId>
38+
<executions>
39+
<execution>
40+
<id>default-compile</id>
41+
<configuration>
42+
<annotationProcessorPaths>
43+
<path>
44+
<groupId>io.quarkus</groupId>
45+
<artifactId>quarkus-extension-processor</artifactId>
46+
<version>${project.version}</version>
47+
</path>
48+
</annotationProcessorPaths>
49+
</configuration>
50+
</execution>
51+
</executions>
52+
</plugin>
53+
</plugins>
54+
</build>
55+
</project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.quarkus.proxy.config.deployment;
2+
3+
import jakarta.inject.Singleton;
4+
5+
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
6+
import io.quarkus.deployment.annotations.BuildProducer;
7+
import io.quarkus.deployment.annotations.BuildStep;
8+
import io.quarkus.deployment.annotations.ExecutionTime;
9+
import io.quarkus.deployment.annotations.Record;
10+
import io.quarkus.proxy.config.ProxyConfig;
11+
import io.quarkus.proxy.config.ProxyConfigurationRegistry;
12+
13+
public class ProxyConfigProcessor {
14+
15+
@BuildStep
16+
@Record(ExecutionTime.RUNTIME_INIT)
17+
void initializeProxyConfigurationRegistry(
18+
ProxyConfigurationRegistry recorder,
19+
ProxyConfig proxyConfig,
20+
BuildProducer<SyntheticBeanBuildItem> syntheticBeans) {
21+
22+
recorder.init(proxyConfig);
23+
syntheticBeans.produce(SyntheticBeanBuildItem
24+
.configure(ProxyConfigurationRegistry.class)
25+
.supplier(recorder.getSupplier())
26+
.scope(Singleton.class)
27+
.unremovable()
28+
.setRuntimeInit()
29+
.done());
30+
31+
}
32+
}

extensions/proxy-registry/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>quarkus-extensions-parent</artifactId>
7+
<groupId>io.quarkus</groupId>
8+
<version>999-SNAPSHOT</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>quarkus-proxy-registry-parent</artifactId>
14+
<name>Quarkus - Proxy Registry</name>
15+
<packaging>pom</packaging>
16+
<modules>
17+
<module>deployment</module>
18+
<module>runtime</module>
19+
</modules>
20+
</project>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>quarkus-proxy-registry-parent</artifactId>
7+
<groupId>io.quarkus</groupId>
8+
<version>999-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>quarkus-proxy-registry</artifactId>
13+
<name>Quarkus - Proxy Registry - Runtime</name>
14+
<description>Proxy Configuration used by other Quarkus extensions</description>
15+
<dependencies>
16+
<dependency>
17+
<groupId>io.quarkus</groupId>
18+
<artifactId>quarkus-arc</artifactId>
19+
</dependency>
20+
<dependency>
21+
<groupId>io.quarkus</groupId>
22+
<artifactId>quarkus-core</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>io.quarkus</groupId>
26+
<artifactId>quarkus-credentials</artifactId>
27+
</dependency>
28+
</dependencies>
29+
30+
<build>
31+
<plugins>
32+
<plugin>
33+
<groupId>io.quarkus</groupId>
34+
<artifactId>quarkus-extension-maven-plugin</artifactId>
35+
</plugin>
36+
<plugin>
37+
<artifactId>maven-compiler-plugin</artifactId>
38+
<executions>
39+
<execution>
40+
<id>default-compile</id>
41+
<configuration>
42+
<annotationProcessorPaths>
43+
<path>
44+
<groupId>io.quarkus</groupId>
45+
<artifactId>quarkus-extension-processor</artifactId>
46+
<version>${project.version}</version>
47+
</path>
48+
</annotationProcessorPaths>
49+
</configuration>
50+
</execution>
51+
</executions>
52+
</plugin>
53+
</plugins>
54+
</build>
55+
</project>
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package io.quarkus.proxy.config;
2+
3+
import java.time.Duration;
4+
import java.util.List;
5+
import java.util.Map;
6+
import java.util.Optional;
7+
import java.util.OptionalInt;
8+
9+
import io.quarkus.credentials.CredentialsProvider;
10+
import io.quarkus.proxy.config.ProxyConfig.NamedProxyConfig;
11+
import io.quarkus.runtime.annotations.ConfigDocDefault;
12+
import io.quarkus.runtime.annotations.ConfigGroup;
13+
import io.quarkus.runtime.annotations.ConfigPhase;
14+
import io.quarkus.runtime.annotations.ConfigRoot;
15+
import io.smallrye.config.ConfigMapping;
16+
import io.smallrye.config.WithDefault;
17+
import io.smallrye.config.WithParentName;
18+
19+
@ConfigMapping(prefix = "quarkus.proxy")
20+
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
21+
public interface ProxyConfig {
22+
23+
static final String NO_PROXY = "none";
24+
25+
@WithParentName
26+
NamedProxyConfig defaultProxyConfig();
27+
28+
@WithParentName
29+
Map<String, NamedProxyConfig> namedProxyConfigs();
30+
31+
@ConfigGroup
32+
public interface NamedProxyConfig {
33+
34+
/**
35+
* Proxy host.
36+
*/
37+
Optional<String> host();
38+
39+
/**
40+
* Proxy port
41+
*/
42+
OptionalInt port();
43+
44+
/**
45+
* The credential provider configuration for the proxy.
46+
* A credential provider offers a way to retrieve the proxy password.
47+
* Note that the credential provider is only used if the password is not set in the configuration.
48+
*/
49+
ProxyCredentialProviderConfig credentialsProvider();
50+
51+
/**
52+
* Proxy username.
53+
* <p>
54+
* See also {@code credentials-provider}
55+
*/
56+
Optional<String> username();
57+
58+
/**
59+
* Proxy password
60+
* <p>
61+
* See also {@code credentials-provider}
62+
*/
63+
Optional<String> password();
64+
65+
/**
66+
* Hostnames or IP addresses to exclude from proxying
67+
*/
68+
Optional<List<String>> nonProxyHosts();
69+
70+
/**
71+
* Proxy connection timeout.
72+
*/
73+
@ConfigDocDefault("10s")
74+
Optional<Duration> proxyConnectTimeout();
75+
76+
/**
77+
* The proxy type. Possible values are: {@code HTTP} (default), {@code SOCKS4} and {@code SOCKS5}.
78+
*/
79+
@WithDefault("http")
80+
ProxyType type();
81+
82+
/**
83+
* @return this {@link NamedProxyConfig} if {@link #type()} returns {@link ProxyType#HTTP}; otherwise throws an
84+
* {@link IllegalStateException}
85+
* @throws IllegalStateException if {@link #type()} does not return {@link ProxyType#HTTP}
86+
*/
87+
default NamedProxyConfig assertHttpType() {
88+
if (type() != ProxyType.HTTP) {
89+
throw new IllegalStateException("Proxy type HTTP is required");
90+
}
91+
return this;
92+
}
93+
94+
static enum ProxyType {
95+
HTTP,
96+
SOCKS4,
97+
SOCKS5;
98+
}
99+
100+
}
101+
102+
@ConfigGroup
103+
interface ProxyCredentialProviderConfig {
104+
105+
/**
106+
* The name of the "credential" bucket (map key -> passwords) to retrieve from the
107+
* {@link io.quarkus.credentials.CredentialsProvider}. If not set, the credential provider will not be used.
108+
* <p>
109+
* A credential provider offers a way to retrieve the key store password as well as alias password.
110+
* Note that the credential provider is only used if the passwords are not set in the configuration.
111+
*/
112+
Optional<String> name();
113+
114+
/**
115+
* The name of the bean providing the credential provider.
116+
* <p>
117+
* The name is used to select the credential provider to use.
118+
* The credential provider must be exposed as a CDI bean and with the {@code @Named} annotation set to the
119+
* configured name to be selected.
120+
* <p>
121+
* If not set, the default credential provider is used.
122+
*/
123+
Optional<String> beanName();
124+
125+
/**
126+
* The key used to retrieve the username from the "credential" bucket.
127+
* <p>
128+
* If username, password or both cannot be retrieved from the credential provider, then a RuntimeException is thrown.
129+
*/
130+
@WithDefault(CredentialsProvider.USER_PROPERTY_NAME)
131+
String usernameKey();
132+
133+
/**
134+
* The key used to retrieve the password from the "credential" bucket.
135+
* <p>
136+
* If username, password or both cannot be retrieved from the credential provider, then a RuntimeException is thrown.
137+
*/
138+
@WithDefault(CredentialsProvider.PASSWORD_PROPERTY_NAME)
139+
String passwordKey();
140+
141+
}
142+
}

0 commit comments

Comments
 (0)