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 com.google.common.collect.ImmutableList; 20 import io.grpc.alts.internal.TransportSecurityCommon.RpcProtocolVersions; 21 import javax.annotation.Nullable; 22 23 /** Handshaker options for creating ALTS client channel. */ 24 public final class AltsClientOptions extends AltsHandshakerOptions { 25 26 // targetName is the server service account name for secure name checking. 27 @Nullable private final String targetName; 28 // targetServiceAccounts contains a list of expected target service accounts. One of these service 29 // accounts should match peer service account in the handshaker result. Otherwise, the handshake 30 // fails. 31 private final ImmutableList<String> targetServiceAccounts; 32 AltsClientOptions(Builder builder)33 private AltsClientOptions(Builder builder) { 34 super(builder.rpcProtocolVersions); 35 targetName = builder.targetName; 36 targetServiceAccounts = builder.targetServiceAccounts; 37 } 38 getTargetName()39 public String getTargetName() { 40 return targetName; 41 } 42 getTargetServiceAccounts()43 public ImmutableList<String> getTargetServiceAccounts() { 44 return targetServiceAccounts; 45 } 46 47 /** Builder for AltsClientOptions. */ 48 public static final class Builder { 49 50 @Nullable private String targetName; 51 @Nullable private RpcProtocolVersions rpcProtocolVersions; 52 private ImmutableList<String> targetServiceAccounts = ImmutableList.of(); 53 setTargetName(String targetName)54 public Builder setTargetName(String targetName) { 55 this.targetName = targetName; 56 return this; 57 } 58 setRpcProtocolVersions(RpcProtocolVersions rpcProtocolVersions)59 public Builder setRpcProtocolVersions(RpcProtocolVersions rpcProtocolVersions) { 60 this.rpcProtocolVersions = rpcProtocolVersions; 61 return this; 62 } 63 setTargetServiceAccounts(ImmutableList<String> targetServiceAccounts)64 public Builder setTargetServiceAccounts(ImmutableList<String> targetServiceAccounts) { 65 this.targetServiceAccounts = targetServiceAccounts; 66 return this; 67 } 68 build()69 public AltsClientOptions build() { 70 return new AltsClientOptions(this); 71 } 72 } 73 } 74