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

Adding option to specify client telemetry proxy with credentials #29197

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 @@ -77,13 +77,28 @@ private ProxyOptions getProxyOptions() {

if (logger.isDebugEnabled()) {
logger.debug(
"Enable proxy with type {}, host {}, port {}",
"Enable proxy with type {}, host {}, port {}, userName {}, password length {}",
type,
proxyOptionsConfig.host,
proxyOptionsConfig.port);
proxyOptionsConfig.port,
proxyOptionsConfig.username,
proxyOptionsConfig.password != null ? proxyOptionsConfig.password.length() : -1
);
}

return new ProxyOptions(type, new InetSocketAddress(proxyOptionsConfig.host, proxyOptionsConfig.port));
ProxyOptions proxyOptions = new ProxyOptions(
type,
new InetSocketAddress(proxyOptionsConfig.host, proxyOptionsConfig.port));

if (!Strings.isNullOrEmpty(proxyOptionsConfig.username) ||
FabianMeiswinkel marked this conversation as resolved.
Show resolved Hide resolved
!Strings.isNullOrEmpty(proxyOptionsConfig.password)) {

proxyOptions.setCredentials(
proxyOptionsConfig.username != null ? proxyOptionsConfig.username : "",
proxyOptionsConfig.password != null ? proxyOptionsConfig.password : "");
}

return proxyOptions;
} catch (JsonProcessingException e) {
logger.error("Failed to parse client telemetry proxy option config", e);
}
Expand All @@ -99,12 +114,18 @@ private static class JsonProxyOptionsConfig {
private int port;
@JsonProperty
private String type;
@JsonProperty
private String username;
@JsonProperty
private String password;

private JsonProxyOptionsConfig() {}
private JsonProxyOptionsConfig(String host, int port, String type) {
private JsonProxyOptionsConfig(String host, int port, String type, String username, String password) {
this.host = host;
this.port = port;
this.type = type;
this.username = username;
this.password = password;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand Down Expand Up @@ -212,9 +213,18 @@ public void buildClientTelemetryConfig() {
String proxyHost = "127.0.0.0";
int proxyPort = 8080;
ProxyOptions proxyOptions = new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
String username = UUID.randomUUID().toString();
String password = UUID.randomUUID().toString();
proxyOptions.setCredentials(username, password);
System.setProperty(
"COSMOS.CLIENT_TELEMETRY_PROXY_OPTIONS_CONFIG",
String.format("{\"type\":\"%s\", \"host\": \"%s\", \"port\": %d}", proxyOptions.getType().toString(), proxyHost, proxyPort));
String.format(
"{\"type\":\"%s\", \"host\": \"%s\", \"port\": %d, \"username\": \"%s\", \"password\":\"%s\"}",
proxyOptions.getType().toString(),
proxyHost,
proxyPort,
username,
password));

CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder()
.endpoint(TestConfigurations.HOST)
Expand All @@ -232,6 +242,8 @@ public void buildClientTelemetryConfig() {
assertThat(clientTelemetryConfig.isClientTelemetryEnabled()).isTrue();
assertThat(clientTelemetryConfig.getProxy().getType()).isEqualTo(proxyOptions.getType());
assertThat(clientTelemetryConfig.getProxy().getAddress()).isEqualTo(proxyOptions.getAddress());
assertThat(clientTelemetryConfig.getProxy().getUsername()).isEqualTo(proxyOptions.getUsername());
assertThat(clientTelemetryConfig.getProxy().getPassword()).isEqualTo(proxyOptions.getPassword());
}

private void validateDirectAndGatewayConnectionConfig(ConnectionPolicy connectionPolicy, CosmosClientBuilder cosmosClientBuilder,
Expand Down