Skip to content

Commit

Permalink
chore: implement one method for checking whether endpoint is secure
Browse files Browse the repository at this point in the history
  • Loading branch information
rishtigupta committed Jan 24, 2025
1 parent a9fc4ba commit f995510
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private static ManagedChannel setupConnection(

// set additional channel options (message size, keepalive, auth, etc)
GrpcChannelOptions.applyGrpcConfigurationToChannelBuilder(
controlConfig, channelBuilder, credentialProvider.isControlEndpointSecure());
controlConfig, channelBuilder, credentialProvider.isEndpointSecure());

final List<ClientInterceptor> clientInterceptors = new ArrayList<>();
clientInterceptors.add(new UserHeaderInterceptor(credentialProvider.getAuthToken(), "cache"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private ManagedChannel setupChannel(
GrpcChannelOptions.applyGrpcConfigurationToChannelBuilder(
configuration.getTransportStrategy().getGrpcConfiguration(),
channelBuilder,
credentialProvider.isCacheEndpointSecure());
credentialProvider.isEndpointSecure());

final Map<Metadata.Key<String>, String> extraHeaders = new HashMap<>();
if (configuration.getReadConcern() != ReadConcern.BALANCED) {
Expand Down
30 changes: 4 additions & 26 deletions momento-sdk/src/main/java/momento/sdk/auth/CredentialProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,43 +51,20 @@ public static CredentialProvider forMomentoLocal() {
*/
public abstract String getControlEndpoint();

/**
* Gets whether the control plane endpoint connection is secure.
*
* @return true if connecting to the control plane endpoint connection with TLS; false if not
* using TLS
*/
public abstract boolean isControlEndpointSecure();

/**
* Gets the endpoint with which the Momento client will connect to the Momento data plane.
*
* @return The endpoint.
*/
public abstract String getCacheEndpoint();

/**
* Gets whether the data plane endpoint connection is secure.
*
* @return true if connecting to the data plane endpoint connection with TLS; false if not using
* TLS
*/
public abstract boolean isCacheEndpointSecure();

/**
* Gets the endpoint with which the Momento client will connect to the Momento storage service.
*
* @return The endpoint.
*/
public abstract String getStorageEndpoint();

/**
* Gets whether the storage endpoint connection is secure.
*
* @return true if connecting to the storage endpoint connection with TLS; false if not using TLS
*/
public abstract boolean isStorageEndpointSecure();

/**
* Gets the token endpoint with which the Momento client will connect to the Momento token
* service.
Expand All @@ -97,11 +74,12 @@ public static CredentialProvider forMomentoLocal() {
public abstract String getTokenEndpoint();

/**
* Gets whether the token endpoint connection is secure.
* Gets whether the endpoint connection is secure.
*
* @return true if connecting to the token endpoint connection with TLS; false if not using TLS
* @return true if connecting to the endpoint connection with TLS; false if not
* using TLS
*/
public abstract boolean isTokenEndpointSecure();
public abstract boolean isEndpointSecure();

/**
* Gets the port with which the Momento client will connect to the Momento local.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,24 @@ public String getCacheEndpoint() {
return cacheEndpoint;
}

@Override
public boolean isCacheEndpointSecure() {
return isSecureConnection(cacheEndpoint);
}

@Override
public String getControlEndpoint() {
return controlEndpoint;
}

@Override
public boolean isControlEndpointSecure() {
return isSecureConnection(controlEndpoint);
}

@Override
public String getTokenEndpoint() {
return tokenEndpoint;
}

@Override
public boolean isTokenEndpointSecure() {
return isSecureConnection(tokenEndpoint);
}

@Override
public String getStorageEndpoint() {
return storageEndpoint;
}

@Override
public boolean isStorageEndpointSecure() {
return isSecureConnection(storageEndpoint);
public boolean isEndpointSecure() {
return isSecureConnection(DEFAULT_HOSTNAME);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,38 +155,23 @@ public String getControlEndpoint() {
return controlEndpoint;
}

@Override
public boolean isControlEndpointSecure() {
return true;
}

@Override
public String getCacheEndpoint() {
return cacheEndpoint;
}

@Override
public boolean isCacheEndpointSecure() {
return true;
}

@Override
public String getStorageEndpoint() {
return storageEndpoint;
}

@Override
public boolean isStorageEndpointSecure() {
return true;
}

@Override
public String getTokenEndpoint() {
return tokenEndpoint;
}

@Override
public boolean isTokenEndpointSecure() {
public boolean isEndpointSecure() {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ public static void applyGrpcConfigurationToChannelBuilder(

public static void applyGrpcConfigurationToChannelBuilder(
IGrpcConfiguration grpcConfig, NettyChannelBuilder channelBuilder, boolean isSecure) {
channelBuilder.disableRetry();

if (isSecure) {
channelBuilder.useTransportSecurity();
channelBuilder.disableRetry();
} else {
channelBuilder.usePlaintext();
}
Expand Down

0 comments on commit f995510

Please sign in to comment.