|
| 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