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

s2a: Combine MtlsToS2ChannelCredentials and S2AChannelCredentials. #11544

Merged
merged 8 commits into from
Sep 30, 2024
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
13 changes: 0 additions & 13 deletions s2a/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,6 @@ java_library(
],
)

java_library(
name = "mtls_to_s2av2_credentials",
srcs = ["src/main/java/io/grpc/s2a/MtlsToS2AChannelCredentials.java"],
visibility = ["//visibility:public"],
deps = [
":s2a_channel_pool",
":s2av2_credentials",
"//api",
"//util",
artifact("com.google.guava:guava"),
],
)

# bazel only accepts proto import with absolute path.
genrule(
name = "protobuf_imports",
Expand Down
89 changes: 0 additions & 89 deletions s2a/src/main/java/io/grpc/s2a/MtlsToS2AChannelCredentials.java

This file was deleted.

25 changes: 9 additions & 16 deletions s2a/src/main/java/io/grpc/s2a/S2AChannelCredentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,20 @@

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.isNullOrEmpty;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.grpc.Channel;
import io.grpc.ChannelCredentials;
import io.grpc.ExperimentalApi;
import io.grpc.InsecureChannelCredentials;
import io.grpc.internal.ObjectPool;
import io.grpc.internal.SharedResourcePool;
import io.grpc.netty.InternalNettyChannelCredentials;
import io.grpc.netty.InternalProtocolNegotiator;
import io.grpc.s2a.channel.S2AHandshakerServiceChannel;
import io.grpc.s2a.handshaker.S2AIdentity;
import io.grpc.s2a.handshaker.S2AProtocolNegotiatorFactory;
import java.io.IOException;
import javax.annotation.concurrent.NotThreadSafe;
import org.checkerframework.checker.nullness.qual.Nullable;

Expand All @@ -46,25 +45,27 @@ public final class S2AChannelCredentials {
* Creates a channel credentials builder for establishing an S2A-secured connection.
*
* @param s2aAddress the address of the S2A server used to secure the connection.
* @param s2aChannelCredentials the credentials to be used when connecting to the S2A.
* @return a {@code S2AChannelCredentials.Builder} instance.
*/
public static Builder newBuilder(String s2aAddress) {
public static Builder newBuilder(String s2aAddress, ChannelCredentials s2aChannelCredentials) {
checkArgument(!isNullOrEmpty(s2aAddress), "S2A address must not be null or empty.");
return new Builder(s2aAddress);
checkNotNull(s2aChannelCredentials, "S2A channel credentials must not be null");
return new Builder(s2aAddress, s2aChannelCredentials);
}

/** Builds an {@code S2AChannelCredentials} instance. */
@NotThreadSafe
public static final class Builder {
private final String s2aAddress;
private final ChannelCredentials s2aChannelCredentials;
private ObjectPool<Channel> s2aChannelPool;
private ChannelCredentials s2aChannelCredentials;
private @Nullable S2AIdentity localIdentity = null;

Builder(String s2aAddress) {
Builder(String s2aAddress, ChannelCredentials s2aChannelCredentials) {
this.s2aAddress = s2aAddress;
this.s2aChannelCredentials = s2aChannelCredentials;
this.s2aChannelPool = null;
this.s2aChannelCredentials = InsecureChannelCredentials.create();
}

/**
Expand Down Expand Up @@ -106,15 +107,7 @@ public Builder setLocalUid(String localUid) {
return this;
}

/** Sets the credentials to be used when connecting to the S2A. */
@CanIgnoreReturnValue
public Builder setS2AChannelCredentials(ChannelCredentials s2aChannelCredentials) {
this.s2aChannelCredentials = s2aChannelCredentials;
return this;
}

public ChannelCredentials build() {
checkState(!isNullOrEmpty(s2aAddress), "S2A address must not be null or empty.");
public ChannelCredentials build() throws IOException {
ObjectPool<Channel> s2aChannelPool =
SharedResourcePool.forResource(
S2AHandshakerServiceChannel.getChannelResource(s2aAddress, s2aChannelCredentials));
Expand Down
135 changes: 0 additions & 135 deletions s2a/src/test/java/io/grpc/s2a/MtlsToS2AChannelCredentialsTest.java

This file was deleted.

Loading