|
|
@ -80,7 +80,8 @@ bool SecureCallCredentials::ApplyToCall(grpc_call* call) { |
|
|
|
return grpc_call_set_credentials(call, c_creds_) == GRPC_CALL_OK; |
|
|
|
return grpc_call_set_credentials(call, c_creds_) == GRPC_CALL_OK; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
namespace internal { |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<ChannelCredentials> WrapChannelCredentials( |
|
|
|
std::shared_ptr<ChannelCredentials> WrapChannelCredentials( |
|
|
|
grpc_channel_credentials* creds) { |
|
|
|
grpc_channel_credentials* creds) { |
|
|
|
return creds == nullptr ? nullptr |
|
|
|
return creds == nullptr ? nullptr |
|
|
@ -88,6 +89,10 @@ std::shared_ptr<ChannelCredentials> WrapChannelCredentials( |
|
|
|
new SecureChannelCredentials(creds)); |
|
|
|
new SecureChannelCredentials(creds)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<CallCredentials> WrapCallCredentials( |
|
|
|
std::shared_ptr<CallCredentials> WrapCallCredentials( |
|
|
|
grpc_call_credentials* creds) { |
|
|
|
grpc_call_credentials* creds) { |
|
|
|
return creds == nullptr ? nullptr |
|
|
|
return creds == nullptr ? nullptr |
|
|
@ -98,7 +103,7 @@ std::shared_ptr<CallCredentials> WrapCallCredentials( |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<ChannelCredentials> GoogleDefaultCredentials() { |
|
|
|
std::shared_ptr<ChannelCredentials> GoogleDefaultCredentials() { |
|
|
|
grpc::GrpcLibraryCodegen init; // To call grpc_init().
|
|
|
|
grpc::GrpcLibraryCodegen init; // To call grpc_init().
|
|
|
|
return WrapChannelCredentials( |
|
|
|
return internal::WrapChannelCredentials( |
|
|
|
grpc_google_default_credentials_create(nullptr)); |
|
|
|
grpc_google_default_credentials_create(nullptr)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -113,7 +118,7 @@ std::shared_ptr<ChannelCredentials> SslCredentials( |
|
|
|
options.pem_root_certs.empty() ? nullptr : options.pem_root_certs.c_str(), |
|
|
|
options.pem_root_certs.empty() ? nullptr : options.pem_root_certs.c_str(), |
|
|
|
options.pem_private_key.empty() ? nullptr : &pem_key_cert_pair, nullptr, |
|
|
|
options.pem_private_key.empty() ? nullptr : &pem_key_cert_pair, nullptr, |
|
|
|
nullptr); |
|
|
|
nullptr); |
|
|
|
return WrapChannelCredentials(c_creds); |
|
|
|
return internal::WrapChannelCredentials(c_creds); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
namespace experimental { |
|
|
|
namespace experimental { |
|
|
@ -278,39 +283,23 @@ std::shared_ptr<ChannelCredentials> AltsCredentials( |
|
|
|
} |
|
|
|
} |
|
|
|
grpc_channel_credentials* c_creds = grpc_alts_credentials_create(c_options); |
|
|
|
grpc_channel_credentials* c_creds = grpc_alts_credentials_create(c_options); |
|
|
|
grpc_alts_credentials_options_destroy(c_options); |
|
|
|
grpc_alts_credentials_options_destroy(c_options); |
|
|
|
return WrapChannelCredentials(c_creds); |
|
|
|
return internal::WrapChannelCredentials(c_creds); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Builds Local Credentials
|
|
|
|
// Builds Local Credentials
|
|
|
|
std::shared_ptr<ChannelCredentials> LocalCredentials( |
|
|
|
std::shared_ptr<ChannelCredentials> LocalCredentials( |
|
|
|
grpc_local_connect_type type) { |
|
|
|
grpc_local_connect_type type) { |
|
|
|
grpc::GrpcLibraryCodegen init; // To call grpc_init().
|
|
|
|
grpc::GrpcLibraryCodegen init; // To call grpc_init().
|
|
|
|
return WrapChannelCredentials(grpc_local_credentials_create(type)); |
|
|
|
return internal::WrapChannelCredentials(grpc_local_credentials_create(type)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Builds TLS Credentials given TLS options.
|
|
|
|
// Builds TLS Credentials given TLS options.
|
|
|
|
std::shared_ptr<ChannelCredentials> TlsCredentials( |
|
|
|
std::shared_ptr<ChannelCredentials> TlsCredentials( |
|
|
|
const TlsCredentialsOptions& options) { |
|
|
|
const TlsCredentialsOptions& options) { |
|
|
|
return WrapChannelCredentials( |
|
|
|
return internal::WrapChannelCredentials( |
|
|
|
grpc_tls_credentials_create(options.c_credentials_options())); |
|
|
|
grpc_tls_credentials_create(options.c_credentials_options())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Builds XDS Credentials
|
|
|
|
|
|
|
|
std::shared_ptr<ChannelCredentials> XdsCredentials( |
|
|
|
|
|
|
|
const std::shared_ptr<ChannelCredentials>& fallback_creds) { |
|
|
|
|
|
|
|
if (fallback_creds->IsInsecure()) { |
|
|
|
|
|
|
|
grpc_channel_credentials* insecure_creds = |
|
|
|
|
|
|
|
grpc_insecure_credentials_create(); |
|
|
|
|
|
|
|
auto xds_creds = |
|
|
|
|
|
|
|
WrapChannelCredentials(grpc_xds_credentials_create(insecure_creds)); |
|
|
|
|
|
|
|
grpc_channel_credentials_release(insecure_creds); |
|
|
|
|
|
|
|
return xds_creds; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return WrapChannelCredentials(grpc_xds_credentials_create( |
|
|
|
|
|
|
|
fallback_creds->AsSecureCredentials()->GetRawCreds())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace experimental
|
|
|
|
} // namespace experimental
|
|
|
|
|
|
|
|
|
|
|
|
// Builds credentials for use when running in GCE
|
|
|
|
// Builds credentials for use when running in GCE
|
|
|
@ -373,8 +362,10 @@ std::shared_ptr<ChannelCredentials> CompositeChannelCredentials( |
|
|
|
channel_creds->AsSecureCredentials(); |
|
|
|
channel_creds->AsSecureCredentials(); |
|
|
|
SecureCallCredentials* s_call_creds = call_creds->AsSecureCredentials(); |
|
|
|
SecureCallCredentials* s_call_creds = call_creds->AsSecureCredentials(); |
|
|
|
if (s_channel_creds && s_call_creds) { |
|
|
|
if (s_channel_creds && s_call_creds) { |
|
|
|
return WrapChannelCredentials(grpc_composite_channel_credentials_create( |
|
|
|
return internal::WrapChannelCredentials( |
|
|
|
s_channel_creds->GetRawCreds(), s_call_creds->GetRawCreds(), nullptr)); |
|
|
|
grpc_composite_channel_credentials_create( |
|
|
|
|
|
|
|
s_channel_creds->GetRawCreds(), s_call_creds->GetRawCreds(), |
|
|
|
|
|
|
|
nullptr)); |
|
|
|
} |
|
|
|
} |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|