@Test public void testProxyConfigFromEnv() { Map<String, String> env = ImmutableMap.of("http_proxy", "https: TDClientBuilder builder = TDClientFactory.clientBuilderFromConfig( DEFAULT_DEFAULT_SYSTEM_CONFIG, env, newConfig(), SECRETS); TDClientConfig clientConfig = builder.buildConfig(); assertThat(clientConfig.proxy.get().getUser(), is(Optional.of("me"))); assertThat(clientConfig.proxy.get().getPassword(), is(Optional.of("'(#%"))); assertThat(clientConfig.proxy.get().getUri(), is(URI.create("https: }
@VisibleForTesting static TDClientBuilder clientBuilderFromConfig(SystemDefaultConfig systemDefaultConfig, Map<String, String> env, Config params, SecretProvider secrets) { TDClientBuilder builder = TDClient.newBuilder(false); boolean useSSL = secrets.getSecretOptional("use_ssl").transform(Boolean::parseBoolean).or(() -> params.get("use_ssl", boolean.class, true)); String scheme = useSSL ? "https" : "http"; SecretProvider proxySecrets = secrets.getSecrets("proxy"); Config proxyConfig = params.getNestedOrGetEmpty("proxy"); boolean proxyEnabled = proxySecrets.getSecretOptional("enabled").transform(Boolean::parseBoolean).or(() -> proxyConfig.get("enabled", Boolean.class, false)); if (proxyEnabled) { builder.setProxy(proxyConfig(proxyConfig, proxySecrets)); } else { Optional<ProxyConfig> config = Proxies.proxyConfigFromEnv(scheme, env); if (config.isPresent()) { builder.setProxy(config.get()); } } Optional<String> apikey = secrets.getSecretOptional("apikey").transform(String::trim); if (!apikey.isPresent()) { throw new ConfigException("The 'td.apikey' secret is missing"); } if (apikey.get().isEmpty()) { throw new ConfigException("The 'td.apikey' secret is empty"); } return builder .setEndpoint(secrets.getSecretOptional("endpoint").or(() -> params.get("endpoint", String.class, systemDefaultConfig.getEndpoint()))) .setUseSSL(useSSL) .setApiKey(apikey.get()) .setRetryLimit(0) ; }
TDClientFactory { @VisibleForTesting static TDClientBuilder clientBuilderFromConfig(SystemDefaultConfig systemDefaultConfig, Map<String, String> env, Config params, SecretProvider secrets) { TDClientBuilder builder = TDClient.newBuilder(false); boolean useSSL = secrets.getSecretOptional("use_ssl").transform(Boolean::parseBoolean).or(() -> params.get("use_ssl", boolean.class, true)); String scheme = useSSL ? "https" : "http"; SecretProvider proxySecrets = secrets.getSecrets("proxy"); Config proxyConfig = params.getNestedOrGetEmpty("proxy"); boolean proxyEnabled = proxySecrets.getSecretOptional("enabled").transform(Boolean::parseBoolean).or(() -> proxyConfig.get("enabled", Boolean.class, false)); if (proxyEnabled) { builder.setProxy(proxyConfig(proxyConfig, proxySecrets)); } else { Optional<ProxyConfig> config = Proxies.proxyConfigFromEnv(scheme, env); if (config.isPresent()) { builder.setProxy(config.get()); } } Optional<String> apikey = secrets.getSecretOptional("apikey").transform(String::trim); if (!apikey.isPresent()) { throw new ConfigException("The 'td.apikey' secret is missing"); } if (apikey.get().isEmpty()) { throw new ConfigException("The 'td.apikey' secret is empty"); } return builder .setEndpoint(secrets.getSecretOptional("endpoint").or(() -> params.get("endpoint", String.class, systemDefaultConfig.getEndpoint()))) .setUseSSL(useSSL) .setApiKey(apikey.get()) .setRetryLimit(0) ; } }
TDClientFactory { @VisibleForTesting static TDClientBuilder clientBuilderFromConfig(SystemDefaultConfig systemDefaultConfig, Map<String, String> env, Config params, SecretProvider secrets) { TDClientBuilder builder = TDClient.newBuilder(false); boolean useSSL = secrets.getSecretOptional("use_ssl").transform(Boolean::parseBoolean).or(() -> params.get("use_ssl", boolean.class, true)); String scheme = useSSL ? "https" : "http"; SecretProvider proxySecrets = secrets.getSecrets("proxy"); Config proxyConfig = params.getNestedOrGetEmpty("proxy"); boolean proxyEnabled = proxySecrets.getSecretOptional("enabled").transform(Boolean::parseBoolean).or(() -> proxyConfig.get("enabled", Boolean.class, false)); if (proxyEnabled) { builder.setProxy(proxyConfig(proxyConfig, proxySecrets)); } else { Optional<ProxyConfig> config = Proxies.proxyConfigFromEnv(scheme, env); if (config.isPresent()) { builder.setProxy(config.get()); } } Optional<String> apikey = secrets.getSecretOptional("apikey").transform(String::trim); if (!apikey.isPresent()) { throw new ConfigException("The 'td.apikey' secret is missing"); } if (apikey.get().isEmpty()) { throw new ConfigException("The 'td.apikey' secret is empty"); } return builder .setEndpoint(secrets.getSecretOptional("endpoint").or(() -> params.get("endpoint", String.class, systemDefaultConfig.getEndpoint()))) .setUseSSL(useSSL) .setApiKey(apikey.get()) .setRetryLimit(0) ; }  }
TDClientFactory { @VisibleForTesting static TDClientBuilder clientBuilderFromConfig(SystemDefaultConfig systemDefaultConfig, Map<String, String> env, Config params, SecretProvider secrets) { TDClientBuilder builder = TDClient.newBuilder(false); boolean useSSL = secrets.getSecretOptional("use_ssl").transform(Boolean::parseBoolean).or(() -> params.get("use_ssl", boolean.class, true)); String scheme = useSSL ? "https" : "http"; SecretProvider proxySecrets = secrets.getSecrets("proxy"); Config proxyConfig = params.getNestedOrGetEmpty("proxy"); boolean proxyEnabled = proxySecrets.getSecretOptional("enabled").transform(Boolean::parseBoolean).or(() -> proxyConfig.get("enabled", Boolean.class, false)); if (proxyEnabled) { builder.setProxy(proxyConfig(proxyConfig, proxySecrets)); } else { Optional<ProxyConfig> config = Proxies.proxyConfigFromEnv(scheme, env); if (config.isPresent()) { builder.setProxy(config.get()); } } Optional<String> apikey = secrets.getSecretOptional("apikey").transform(String::trim); if (!apikey.isPresent()) { throw new ConfigException("The 'td.apikey' secret is missing"); } if (apikey.get().isEmpty()) { throw new ConfigException("The 'td.apikey' secret is empty"); } return builder .setEndpoint(secrets.getSecretOptional("endpoint").or(() -> params.get("endpoint", String.class, systemDefaultConfig.getEndpoint()))) .setUseSSL(useSSL) .setApiKey(apikey.get()) .setRetryLimit(0) ; }   }
TDClientFactory { @VisibleForTesting static TDClientBuilder clientBuilderFromConfig(SystemDefaultConfig systemDefaultConfig, Map<String, String> env, Config params, SecretProvider secrets) { TDClientBuilder builder = TDClient.newBuilder(false); boolean useSSL = secrets.getSecretOptional("use_ssl").transform(Boolean::parseBoolean).or(() -> params.get("use_ssl", boolean.class, true)); String scheme = useSSL ? "https" : "http"; SecretProvider proxySecrets = secrets.getSecrets("proxy"); Config proxyConfig = params.getNestedOrGetEmpty("proxy"); boolean proxyEnabled = proxySecrets.getSecretOptional("enabled").transform(Boolean::parseBoolean).or(() -> proxyConfig.get("enabled", Boolean.class, false)); if (proxyEnabled) { builder.setProxy(proxyConfig(proxyConfig, proxySecrets)); } else { Optional<ProxyConfig> config = Proxies.proxyConfigFromEnv(scheme, env); if (config.isPresent()) { builder.setProxy(config.get()); } } Optional<String> apikey = secrets.getSecretOptional("apikey").transform(String::trim); if (!apikey.isPresent()) { throw new ConfigException("The 'td.apikey' secret is missing"); } if (apikey.get().isEmpty()) { throw new ConfigException("The 'td.apikey' secret is empty"); } return builder .setEndpoint(secrets.getSecretOptional("endpoint").or(() -> params.get("endpoint", String.class, systemDefaultConfig.getEndpoint()))) .setUseSSL(useSSL) .setApiKey(apikey.get()) .setRetryLimit(0) ; }    }