vitess.io/vitess@v0.16.2/go/vt/vtctl/grpcclientcommon/dial_option.go (about) 1 /* 2 Copyright 2021 The Vitess 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 grpcclientcommon defines the flags shared by both grpcvtctlclient and 18 // grpcvtctldclient. 19 package grpcclientcommon 20 21 import ( 22 "github.com/spf13/pflag" 23 "google.golang.org/grpc" 24 25 "vitess.io/vitess/go/vt/grpcclient" 26 "vitess.io/vitess/go/vt/servenv" 27 ) 28 29 var cert, key, ca, crl, name string 30 31 func init() { 32 servenv.OnParseFor("vtctl", RegisterFlags) 33 servenv.OnParseFor("vttestserver", RegisterFlags) 34 servenv.OnParseFor("vtctlclient", RegisterFlags) 35 servenv.OnParseFor("vtctldclient", RegisterFlags) 36 } 37 38 func RegisterFlags(fs *pflag.FlagSet) { 39 fs.StringVar(&cert, "vtctld_grpc_cert", cert, "the cert to use to connect") 40 fs.StringVar(&key, "vtctld_grpc_key", key, "the key to use to connect") 41 fs.StringVar(&ca, "vtctld_grpc_ca", ca, "the server ca to use to validate servers when connecting") 42 fs.StringVar(&crl, "vtctld_grpc_crl", crl, "the server crl to use to validate server certificates when connecting") 43 fs.StringVar(&name, "vtctld_grpc_server_name", name, "the server name to use to validate server certificate") 44 } 45 46 // SecureDialOption returns a grpc.DialOption configured to use TLS (or 47 // insecure if no flags were set) based on the vtctld_grpc_* flags declared by 48 // this package. 49 func SecureDialOption() (grpc.DialOption, error) { 50 return grpcclient.SecureDialOption(cert, key, ca, crl, name) 51 }