• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 The gRPC Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.grpc.alts;
18 
19 import io.grpc.ForwardingChannelBuilder;
20 import io.grpc.ManagedChannelBuilder;
21 import io.grpc.internal.GrpcUtil;
22 import io.grpc.netty.NettyChannelBuilder;
23 
24 /**
25  * {@code ManagedChannelBuilder} for Google Compute Engine. This class sets up a secure channel
26  * using ALTS if applicable and using TLS as fallback.
27  */
28 public final class ComputeEngineChannelBuilder
29     extends ForwardingChannelBuilder<ComputeEngineChannelBuilder> {
30 
31   private final NettyChannelBuilder delegate;
32 
ComputeEngineChannelBuilder(String target)33   private ComputeEngineChannelBuilder(String target) {
34     delegate = NettyChannelBuilder.forTarget(target, ComputeEngineChannelCredentials.create());
35   }
36 
37   /** "Overrides" the static method in {@link ManagedChannelBuilder}. */
forTarget(String target)38   public static final ComputeEngineChannelBuilder forTarget(String target) {
39     return new ComputeEngineChannelBuilder(target);
40   }
41 
42   /** "Overrides" the static method in {@link ManagedChannelBuilder}. */
forAddress(String name, int port)43   public static ComputeEngineChannelBuilder forAddress(String name, int port) {
44     return forTarget(GrpcUtil.authorityFromHostAndPort(name, port));
45   }
46 
47   @Override
delegate()48   protected NettyChannelBuilder delegate() {
49     return delegate;
50   }
51 }
52