add local creds to grpc_cli

pull/23037/head
yihuaz 5 years ago
parent 9facfe2b68
commit 1d69b7d676
  1. 28
      test/cpp/util/cli_credentials.cc

@ -47,10 +47,14 @@ DEFINE_string(
ssl_client_key, "", ssl_client_key, "",
"If not empty, load this PEM formatted private key. Requires use of " "If not empty, load this PEM formatted private key. Requires use of "
"--ssl_client_cert"); "--ssl_client_cert");
DEFINE_string(
local_connect_type, "local_tcp",
"The type of local connections for which local channel credentials will "
"be applied. Should be local_tcp or uds.");
DEFINE_string( DEFINE_string(
channel_creds_type, "", channel_creds_type, "",
"The channel creds type: insecure, ssl, gdc (Google Default Credentials) " "The channel creds type: insecure, ssl, gdc (Google Default Credentials), "
"or alts."); "alts, or local.");
DEFINE_string( DEFINE_string(
call_creds, "", call_creds, "",
"Call credentials to use: none (default), or access_token=<token>. If " "Call credentials to use: none (default), or access_token=<token>. If "
@ -138,10 +142,20 @@ CliCredentials::GetChannelCredentials() const {
} else if (FLAGS_channel_creds_type.compare("alts") == 0) { } else if (FLAGS_channel_creds_type.compare("alts") == 0) {
return grpc::experimental::AltsCredentials( return grpc::experimental::AltsCredentials(
grpc::experimental::AltsCredentialsOptions()); grpc::experimental::AltsCredentialsOptions());
} else if (FLAGS_channel_creds_type.compare("local") == 0) {
if (FLAGS_local_connect_type.compare("local_tcp") == 0) {
return grpc::experimental::LocalCredentials(LOCAL_TCP);
} else if (FLAGS_local_connect_type.compare("uds") == 0) {
return grpc::experimental::LocalCredentials(UDS);
} else {
fprintf(stderr,
"--local_connect_type=%s invalid; must be local_tcp or uds.\n",
FLAGS_local_connect_type.c_str());
}
} }
fprintf(stderr, fprintf(stderr,
"--channel_creds_type=%s invalid; must be insecure, ssl, gdc or " "--channel_creds_type=%s invalid; must be insecure, ssl, gdc, "
"alts.\n", "alts, or local.\n",
FLAGS_channel_creds_type.c_str()); FLAGS_channel_creds_type.c_str());
return std::shared_ptr<grpc::ChannelCredentials>(); return std::shared_ptr<grpc::ChannelCredentials>();
} }
@ -203,7 +217,8 @@ std::shared_ptr<grpc::ChannelCredentials> CliCredentials::GetCredentials()
} }
const grpc::string CliCredentials::GetCredentialUsage() const { const grpc::string CliCredentials::GetCredentialUsage() const {
return " --enable_ssl ; Set whether to use ssl (deprecated)\n" return " --enable_ssl ; Set whether to use ssl "
"(deprecated)\n"
" --use_auth ; Set whether to create default google" " --use_auth ; Set whether to create default google"
" credentials\n" " credentials\n"
" ; (deprecated)\n" " ; (deprecated)\n"
@ -213,7 +228,8 @@ const grpc::string CliCredentials::GetCredentialUsage() const {
" --ssl_target ; Set server host for ssl validation\n" " --ssl_target ; Set server host for ssl validation\n"
" --ssl_client_cert ; Client cert for ssl\n" " --ssl_client_cert ; Client cert for ssl\n"
" --ssl_client_key ; Client private key for ssl\n" " --ssl_client_key ; Client private key for ssl\n"
" --channel_creds_type ; Set to insecure, ssl, gdc, or alts\n" " --local_connect_type ; Set to local_tcp or uds\n"
" --channel_creds_type ; Set to insecure, ssl, gdc, alts, or local\n"
" --call_creds ; Set to none, or" " --call_creds ; Set to none, or"
" access_token=<token>\n"; " access_token=<token>\n";
} }

Loading…
Cancel
Save