ALTS version of ManagedChannelBuilder. This class sets up a secure and authenticated communication between two cloud VMs using ALTS.
| 32 | * communication between two cloud VMs using ALTS. |
| 33 | */ |
| 34 | @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4151") |
| 35 | public final class AltsChannelBuilder extends ForwardingChannelBuilder2<AltsChannelBuilder> { |
| 36 | private final NettyChannelBuilder delegate; |
| 37 | private final AltsChannelCredentials.Builder credentialsBuilder = |
| 38 | new AltsChannelCredentials.Builder(); |
| 39 | |
| 40 | /** "Overrides" the static method in {@link ManagedChannelBuilder}. */ |
| 41 | public static AltsChannelBuilder forTarget(String target) { |
| 42 | return new AltsChannelBuilder(target); |
| 43 | } |
| 44 | |
| 45 | /** "Overrides" the static method in {@link ManagedChannelBuilder}. */ |
| 46 | public static AltsChannelBuilder forAddress(String name, int port) { |
| 47 | return forTarget(GrpcUtil.authorityFromHostAndPort(name, port)); |
| 48 | } |
| 49 | |
| 50 | private AltsChannelBuilder(String target) { |
| 51 | delegate = NettyChannelBuilder.forTarget(target); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Adds an expected target service accounts. One of the added service accounts should match peer |
| 56 | * service account in the handshaker result. Otherwise, the handshake fails. |
| 57 | */ |
| 58 | public AltsChannelBuilder addTargetServiceAccount(String targetServiceAccount) { |
| 59 | credentialsBuilder.addTargetServiceAccount(targetServiceAccount); |
| 60 | return this; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Enables untrusted ALTS for testing. If this function is called, we will not check whether ALTS |
| 65 | * is running on Google Cloud Platform. |
| 66 | */ |
| 67 | public AltsChannelBuilder enableUntrustedAltsForTesting() { |
| 68 | credentialsBuilder.enableUntrustedAltsForTesting(); |
| 69 | return this; |
| 70 | } |
| 71 | |
| 72 | /** Sets a new handshaker service address for testing. */ |
| 73 | public AltsChannelBuilder setHandshakerAddressForTesting(String handshakerAddress) { |
| 74 | credentialsBuilder.setHandshakerAddressForTesting(handshakerAddress); |
| 75 | return this; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | protected NettyChannelBuilder delegate() { |
| 80 | return delegate; |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public ManagedChannel build() { |
| 85 | InternalNettyChannelBuilder.setProtocolNegotiatorFactory( |
| 86 | delegate(), |
| 87 | credentialsBuilder.buildProtocolNegotiatorFactory()); |
| 88 | |
| 89 | return delegate().build(); |
| 90 | } |
| 91 |
nothing calls this directly
no outgoing calls
no test coverage detected