Skip to content

Commit

Permalink
Add support for disabling TLS (#150)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
rohanshah18 authored Sep 13, 2024
1 parent 987154c commit c75a0df
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
19 changes: 19 additions & 0 deletions src/main/java/io/pinecone/configs/PineconeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()) {
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/io/pinecone/configs/PineconeConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c75a0df

Please sign in to comment.