• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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.internal;
18 
19 import io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.List;
23 import javax.annotation.Nullable;
24 
25 /** Handshaker options for creating ALTS client channel. */
26 public final class AltsClientOptions extends AltsHandshakerOptions {
27   // targetName is the server service account name for secure name checking. This field is not yet
28   // supported.
29   @Nullable private final String targetName;
30   // targetServiceAccounts contains a list of expected target service accounts. One of these service
31   // accounts should match peer service account in the handshaker result. Otherwise, the handshake
32   // fails.
33   private final List<String> targetServiceAccounts;
34 
AltsClientOptions(Builder builder)35   private AltsClientOptions(Builder builder) {
36     super(builder.rpcProtocolVersions);
37     targetName = builder.targetName;
38     targetServiceAccounts =
39         Collections.unmodifiableList(new ArrayList<>(builder.targetServiceAccounts));
40   }
41 
getTargetName()42   public String getTargetName() {
43     return targetName;
44   }
45 
getTargetServiceAccounts()46   public List<String> getTargetServiceAccounts() {
47     return targetServiceAccounts;
48   }
49 
50   /** Builder for AltsClientOptions. */
51   public static final class Builder {
52     @Nullable private String targetName;
53     @Nullable private RpcProtocolVersions rpcProtocolVersions;
54     private ArrayList<String> targetServiceAccounts = new ArrayList<>();
55 
setTargetName(String targetName)56     public Builder setTargetName(String targetName) {
57       this.targetName = targetName;
58       return this;
59     }
60 
setRpcProtocolVersions(RpcProtocolVersions rpcProtocolVersions)61     public Builder setRpcProtocolVersions(RpcProtocolVersions rpcProtocolVersions) {
62       this.rpcProtocolVersions = rpcProtocolVersions;
63       return this;
64     }
65 
addTargetServiceAccount(String targetServiceAccount)66     public Builder addTargetServiceAccount(String targetServiceAccount) {
67       targetServiceAccounts.add(targetServiceAccount);
68       return this;
69     }
70 
build()71     public AltsClientOptions build() {
72       return new AltsClientOptions(this);
73     }
74   }
75 }
76