Skip to content

Commit a140e1b

Browse files
authored
s2a: Combine MtlsToS2ChannelCredentials and S2AChannelCredentials. (#11544)
* Combine MtlsToS2ChannelCredentials and S2AChannelCredentials. * Check if file exists. * S2AChannelCredentials API requires credentials used for client-s2a channel. * remove MtlsToS2A library in BUILD. * Don't check state twice. * Don't check for file existence in tests.
1 parent 795e2cc commit a140e1b

File tree

6 files changed

+79
-286
lines changed

6 files changed

+79
-286
lines changed

s2a/BUILD.bazel

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,6 @@ java_library(
117117
],
118118
)
119119

120-
java_library(
121-
name = "mtls_to_s2av2_credentials",
122-
srcs = ["src/main/java/io/grpc/s2a/MtlsToS2AChannelCredentials.java"],
123-
visibility = ["//visibility:public"],
124-
deps = [
125-
":s2a_channel_pool",
126-
":s2av2_credentials",
127-
"//api",
128-
"//util",
129-
artifact("com.google.guava:guava"),
130-
],
131-
)
132-
133120
# bazel only accepts proto import with absolute path.
134121
genrule(
135122
name = "protobuf_imports",

s2a/src/main/java/io/grpc/s2a/MtlsToS2AChannelCredentials.java

Lines changed: 0 additions & 89 deletions
This file was deleted.

s2a/src/main/java/io/grpc/s2a/S2AChannelCredentials.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,20 @@
1818

1919
import static com.google.common.base.Preconditions.checkArgument;
2020
import static com.google.common.base.Preconditions.checkNotNull;
21-
import static com.google.common.base.Preconditions.checkState;
2221
import static com.google.common.base.Strings.isNullOrEmpty;
2322

2423
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2524
import io.grpc.Channel;
2625
import io.grpc.ChannelCredentials;
2726
import io.grpc.ExperimentalApi;
28-
import io.grpc.InsecureChannelCredentials;
2927
import io.grpc.internal.ObjectPool;
3028
import io.grpc.internal.SharedResourcePool;
3129
import io.grpc.netty.InternalNettyChannelCredentials;
3230
import io.grpc.netty.InternalProtocolNegotiator;
3331
import io.grpc.s2a.channel.S2AHandshakerServiceChannel;
3432
import io.grpc.s2a.handshaker.S2AIdentity;
3533
import io.grpc.s2a.handshaker.S2AProtocolNegotiatorFactory;
34+
import java.io.IOException;
3635
import javax.annotation.concurrent.NotThreadSafe;
3736
import org.checkerframework.checker.nullness.qual.Nullable;
3837

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

5657
/** Builds an {@code S2AChannelCredentials} instance. */
5758
@NotThreadSafe
5859
public static final class Builder {
5960
private final String s2aAddress;
61+
private final ChannelCredentials s2aChannelCredentials;
6062
private ObjectPool<Channel> s2aChannelPool;
61-
private ChannelCredentials s2aChannelCredentials;
6263
private @Nullable S2AIdentity localIdentity = null;
6364

64-
Builder(String s2aAddress) {
65+
Builder(String s2aAddress, ChannelCredentials s2aChannelCredentials) {
6566
this.s2aAddress = s2aAddress;
67+
this.s2aChannelCredentials = s2aChannelCredentials;
6668
this.s2aChannelPool = null;
67-
this.s2aChannelCredentials = InsecureChannelCredentials.create();
6869
}
6970

7071
/**
@@ -106,15 +107,7 @@ public Builder setLocalUid(String localUid) {
106107
return this;
107108
}
108109

109-
/** Sets the credentials to be used when connecting to the S2A. */
110-
@CanIgnoreReturnValue
111-
public Builder setS2AChannelCredentials(ChannelCredentials s2aChannelCredentials) {
112-
this.s2aChannelCredentials = s2aChannelCredentials;
113-
return this;
114-
}
115-
116-
public ChannelCredentials build() {
117-
checkState(!isNullOrEmpty(s2aAddress), "S2A address must not be null or empty.");
110+
public ChannelCredentials build() throws IOException {
118111
ObjectPool<Channel> s2aChannelPool =
119112
SharedResourcePool.forResource(
120113
S2AHandshakerServiceChannel.getChannelResource(s2aAddress, s2aChannelCredentials));

s2a/src/test/java/io/grpc/s2a/MtlsToS2AChannelCredentialsTest.java

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)