From c75a0dfe47bc90fe22aae171be4ec00a96e2300a Mon Sep 17 00:00:00 2001 From: Rohan Shah Date: Fri, 13 Sep 2024 11:01:47 -0400 Subject: [PATCH] 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. --- .../io/pinecone/configs/PineconeConfig.java | 19 +++++++++++++++++++ .../pinecone/configs/PineconeConnection.java | 18 +++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/pinecone/configs/PineconeConfig.java b/src/main/java/io/pinecone/configs/PineconeConfig.java index 49e68aea..192191e2 100644 --- a/src/main/java/io/pinecone/configs/PineconeConfig.java +++ b/src/main/java/io/pinecone/configs/PineconeConfig.java @@ -52,6 +52,7 @@ public class PineconeConfig { private String sourceTag; private ProxyConfig proxyConfig; private ManagedChannel customManagedChannel; + private boolean enableTLS = true; /** * Constructs a {@link PineconeConfig} instance with the specified API key. @@ -207,6 +208,24 @@ public String getUserAgent() { return buildUserAgent(); } + /** + * Returns true if TLS is enabled or false otherwise. + * + * @return enableTls + */ + public boolean isTLSEnabled() { + return enableTLS; + } + + /** + * Sets whether TLS is enabled. + * + * @param enableTLS true to enable TLS, false to disable it. + */ + public void setTLSEnabled(boolean enableTLS) { + this.enableTLS = enableTLS; + } + private String buildUserAgent() { String userAgent = String.format("lang=java; %s=%s", "pineconeClientVersion", pineconeClientVersion); if (this.getSourceTag() != null && !this.getSourceTag().isEmpty()) { diff --git a/src/main/java/io/pinecone/configs/PineconeConnection.java b/src/main/java/io/pinecone/configs/PineconeConnection.java index ffd046eb..5881e5dc 100644 --- a/src/main/java/io/pinecone/configs/PineconeConnection.java +++ b/src/main/java/io/pinecone/configs/PineconeConnection.java @@ -136,13 +136,21 @@ private void onConnectivityStateChanged() { private ManagedChannel buildChannel() { String endpoint = formatEndpoint(config.getHost()); - NettyChannelBuilder builder = NettyChannelBuilder.forTarget(endpoint); + NettyChannelBuilder builder = NettyChannelBuilder + .forTarget(endpoint) + .userAgent(config.getUserAgent()); try { - builder = builder.overrideAuthority(endpoint) - .negotiationType(NegotiationType.TLS) - .sslContext(GrpcSslContexts.forClient().build()) - .userAgent(config.getUserAgent()); + if(config.isTLSEnabled()) { + builder = builder + .overrideAuthority(endpoint) + .negotiationType(NegotiationType.TLS) + .sslContext(GrpcSslContexts.forClient().build()); + } + else { + builder = builder + .negotiationType(NegotiationType.PLAINTEXT); + } if(config.getProxyConfig() != null) { ProxyDetector proxyDetector = getProxyDetector();