From 1d69b7d67684c13b6beef04ecd9f248f31acc94e Mon Sep 17 00:00:00 2001 From: yihuaz Date: Sun, 24 May 2020 15:01:14 -0700 Subject: [PATCH] add local creds to grpc_cli --- test/cpp/util/cli_credentials.cc | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/test/cpp/util/cli_credentials.cc b/test/cpp/util/cli_credentials.cc index 1f7af81a331..0c8414b3c7c 100644 --- a/test/cpp/util/cli_credentials.cc +++ b/test/cpp/util/cli_credentials.cc @@ -47,10 +47,14 @@ DEFINE_string( ssl_client_key, "", "If not empty, load this PEM formatted private key. Requires use of " "--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( channel_creds_type, "", - "The channel creds type: insecure, ssl, gdc (Google Default Credentials) " - "or alts."); + "The channel creds type: insecure, ssl, gdc (Google Default Credentials), " + "alts, or local."); DEFINE_string( call_creds, "", "Call credentials to use: none (default), or access_token=. If " @@ -138,10 +142,20 @@ CliCredentials::GetChannelCredentials() const { } else if (FLAGS_channel_creds_type.compare("alts") == 0) { return grpc::experimental::AltsCredentials( 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, - "--channel_creds_type=%s invalid; must be insecure, ssl, gdc or " - "alts.\n", + "--channel_creds_type=%s invalid; must be insecure, ssl, gdc, " + "alts, or local.\n", FLAGS_channel_creds_type.c_str()); return std::shared_ptr(); } @@ -203,7 +217,8 @@ std::shared_ptr CliCredentials::GetCredentials() } 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" " credentials\n" " ; (deprecated)\n" @@ -213,7 +228,8 @@ const grpc::string CliCredentials::GetCredentialUsage() const { " --ssl_target ; Set server host for ssl validation\n" " --ssl_client_cert ; Client cert 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" " access_token=\n"; }