Skip to content

Commit c75a0df

Browse files
authored
Add support for disabling TLS (#150)
## Problem Add support for enabling/disabling TLS. ## Solution Added enableTls boolean flag which is set to true by default but when set to false, it will be disabled. ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [X] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [ ] Infrastructure change (CI configs, etc) - [ ] Non-code change (docs, etc) - [ ] None of the above: (explain here) ## Test Plan Since the flag is set to true by default, the existing integration tests should work as it is.
1 parent 987154c commit c75a0df

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/main/java/io/pinecone/configs/PineconeConfig.java

+19
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class PineconeConfig {
5252
private String sourceTag;
5353
private ProxyConfig proxyConfig;
5454
private ManagedChannel customManagedChannel;
55+
private boolean enableTLS = true;
5556

5657
/**
5758
* Constructs a {@link PineconeConfig} instance with the specified API key.
@@ -207,6 +208,24 @@ public String getUserAgent() {
207208
return buildUserAgent();
208209
}
209210

211+
/**
212+
* Returns true if TLS is enabled or false otherwise.
213+
*
214+
* @return enableTls
215+
*/
216+
public boolean isTLSEnabled() {
217+
return enableTLS;
218+
}
219+
220+
/**
221+
* Sets whether TLS is enabled.
222+
*
223+
* @param enableTLS true to enable TLS, false to disable it.
224+
*/
225+
public void setTLSEnabled(boolean enableTLS) {
226+
this.enableTLS = enableTLS;
227+
}
228+
210229
private String buildUserAgent() {
211230
String userAgent = String.format("lang=java; %s=%s", "pineconeClientVersion", pineconeClientVersion);
212231
if (this.getSourceTag() != null && !this.getSourceTag().isEmpty()) {

src/main/java/io/pinecone/configs/PineconeConnection.java

+13-5
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,21 @@ private void onConnectivityStateChanged() {
136136

137137
private ManagedChannel buildChannel() {
138138
String endpoint = formatEndpoint(config.getHost());
139-
NettyChannelBuilder builder = NettyChannelBuilder.forTarget(endpoint);
139+
NettyChannelBuilder builder = NettyChannelBuilder
140+
.forTarget(endpoint)
141+
.userAgent(config.getUserAgent());
140142

141143
try {
142-
builder = builder.overrideAuthority(endpoint)
143-
.negotiationType(NegotiationType.TLS)
144-
.sslContext(GrpcSslContexts.forClient().build())
145-
.userAgent(config.getUserAgent());
144+
if(config.isTLSEnabled()) {
145+
builder = builder
146+
.overrideAuthority(endpoint)
147+
.negotiationType(NegotiationType.TLS)
148+
.sslContext(GrpcSslContexts.forClient().build());
149+
}
150+
else {
151+
builder = builder
152+
.negotiationType(NegotiationType.PLAINTEXT);
153+
}
146154

147155
if(config.getProxyConfig() != null) {
148156
ProxyDetector proxyDetector = getProxyDetector();

0 commit comments

Comments
 (0)