From acc6ba0c2456d51fef133008ec9a3aac1451d521 Mon Sep 17 00:00:00 2001 From: Yihua Zhang Date: Tue, 24 Jul 2018 12:00:49 -0700 Subject: [PATCH] Add C++ wrapper for local credentials --- include/grpc/grpc_security.h | 6 ------ include/grpc/grpc_security_constants.h | 6 ++++++ include/grpcpp/security/credentials.h | 5 +++++ include/grpcpp/security/server_credentials.h | 4 ++++ src/cpp/client/secure_credentials.cc | 7 +++++++ src/cpp/server/secure_server_credentials.cc | 6 ++++++ 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/include/grpc/grpc_security.h b/include/grpc/grpc_security.h index 102d20fcf98..02d87a493a1 100644 --- a/include/grpc/grpc_security.h +++ b/include/grpc/grpc_security.h @@ -587,12 +587,6 @@ GRPCAPI grpc_server_credentials* grpc_alts_server_credentials_create( /** --- Local channel/server credentials --- **/ -/** - * Type of local connection for which local channel/server credentials will be - * applied. It only supports UDS for now. - */ -typedef enum { UDS = 0 } grpc_local_connect_type; - /** * This method creates a local channel credential object. It is used for * experimental purpose for now and subject to change. diff --git a/include/grpc/grpc_security_constants.h b/include/grpc/grpc_security_constants.h index 92580ea35e9..944a1e927f0 100644 --- a/include/grpc/grpc_security_constants.h +++ b/include/grpc/grpc_security_constants.h @@ -100,6 +100,12 @@ typedef enum { GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY } grpc_ssl_client_certificate_request_type; +/** + * Type of local connection for which local channel/server credentials will be + * applied. It only supports UDS for now. + */ +typedef enum { UDS = 0 } grpc_local_connect_type; + #ifdef __cplusplus } #endif diff --git a/include/grpcpp/security/credentials.h b/include/grpcpp/security/credentials.h index 36d95d1b426..bfadc15df57 100644 --- a/include/grpcpp/security/credentials.h +++ b/include/grpcpp/security/credentials.h @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -234,6 +235,10 @@ struct AltsCredentialsOptions { std::shared_ptr AltsCredentials( const AltsCredentialsOptions& options); +/// Builds Local Credentials. +std::shared_ptr LocalCredentials( + grpc_local_connect_type type); + } // namespace experimental } // namespace grpc diff --git a/include/grpcpp/security/server_credentials.h b/include/grpcpp/security/server_credentials.h index cf57e275f59..bd00a0a1737 100644 --- a/include/grpcpp/security/server_credentials.h +++ b/include/grpcpp/security/server_credentials.h @@ -97,6 +97,10 @@ struct AltsServerCredentialsOptions { std::shared_ptr AltsServerCredentials( const AltsServerCredentialsOptions& options); +/// Builds Local ServerCredentials. +std::shared_ptr LocalServerCredentials( + grpc_local_connect_type type); + } // namespace experimental } // namespace grpc diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index bdb63596326..e48fbeb86d7 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -107,6 +107,13 @@ std::shared_ptr AltsCredentials( return WrapChannelCredentials(c_creds); } +// Builds Local Credentials +std::shared_ptr LocalCredentials( + grpc_local_connect_type type) { + GrpcLibraryCodegen init; // To call grpc_init(). + return WrapChannelCredentials(grpc_local_credentials_create(type)); +} + } // namespace experimental // Builds credentials for use when running in GCE diff --git a/src/cpp/server/secure_server_credentials.cc b/src/cpp/server/secure_server_credentials.cc index a5af25751af..536bf022dde 100644 --- a/src/cpp/server/secure_server_credentials.cc +++ b/src/cpp/server/secure_server_credentials.cc @@ -139,5 +139,11 @@ std::shared_ptr AltsServerCredentials( new SecureServerCredentials(c_creds)); } +std::shared_ptr LocalServerCredentials( + grpc_local_connect_type type) { + return std::shared_ptr( + new SecureServerCredentials(grpc_local_server_credentials_create(type))); +} + } // namespace experimental } // namespace grpc