aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp/client
diff options
context:
space:
mode:
authorGravatar Julien Boeuf <jboeuf@google.com>2015-10-12 13:26:21 -0700
committerGravatar Julien Boeuf <jboeuf@google.com>2015-10-12 14:09:03 -0700
commit54a902ed17a69c671e5212b115fe5f219654240a (patch)
tree875e994f7662efb8b77e82ad5d1efea36647d091 /src/cpp/client
parent26bf71ce37d39bb3dd2c1ae01fa837db8a082799 (diff)
Successfully compile C++ libary (not tests yet).
Diffstat (limited to 'src/cpp/client')
-rw-r--r--src/cpp/client/create_channel.cc6
-rw-r--r--src/cpp/client/credentials.cc4
-rw-r--r--src/cpp/client/insecure_credentials.cc12
-rw-r--r--src/cpp/client/secure_credentials.cc82
-rw-r--r--src/cpp/client/secure_credentials.h33
5 files changed, 83 insertions, 54 deletions
diff --git a/src/cpp/client/create_channel.cc b/src/cpp/client/create_channel.cc
index d2b2d30126..3bbca807d3 100644
--- a/src/cpp/client/create_channel.cc
+++ b/src/cpp/client/create_channel.cc
@@ -44,12 +44,14 @@ namespace grpc {
class ChannelArguments;
std::shared_ptr<Channel> CreateChannel(
- const grpc::string& target, const std::shared_ptr<Credentials>& creds) {
+ const grpc::string& target,
+ const std::shared_ptr<ChannelCredentials>& creds) {
return CreateCustomChannel(target, creds, ChannelArguments());
}
std::shared_ptr<Channel> CreateCustomChannel(
- const grpc::string& target, const std::shared_ptr<Credentials>& creds,
+ const grpc::string& target,
+ const std::shared_ptr<ChannelCredentials>& creds,
const ChannelArguments& args) {
GrpcLibrary init_lib; // We need to call init in case of a bad creds.
ChannelArguments cp_args = args;
diff --git a/src/cpp/client/credentials.cc b/src/cpp/client/credentials.cc
index 7a8149e9c7..0c08db11a9 100644
--- a/src/cpp/client/credentials.cc
+++ b/src/cpp/client/credentials.cc
@@ -35,6 +35,8 @@
namespace grpc {
-Credentials::~Credentials() {}
+ChannelCredentials::~ChannelCredentials() {}
+
+CallCredentials::~CallCredentials() {}
} // namespace grpc
diff --git a/src/cpp/client/insecure_credentials.cc b/src/cpp/client/insecure_credentials.cc
index c476f3ce95..563fa9267d 100644
--- a/src/cpp/client/insecure_credentials.cc
+++ b/src/cpp/client/insecure_credentials.cc
@@ -43,7 +43,7 @@
namespace grpc {
namespace {
-class InsecureCredentialsImpl GRPC_FINAL : public Credentials {
+class InsecureChannelCredentialsImpl GRPC_FINAL : public ChannelCredentials {
public:
std::shared_ptr<grpc::Channel> CreateChannel(
const string& target, const grpc::ChannelArguments& args) GRPC_OVERRIDE {
@@ -54,15 +54,13 @@ class InsecureCredentialsImpl GRPC_FINAL : public Credentials {
grpc_insecure_channel_create(target.c_str(), &channel_args, nullptr));
}
- // InsecureCredentials should not be applied to a call.
- bool ApplyToCall(grpc_call* call) GRPC_OVERRIDE { return false; }
-
- SecureCredentials* AsSecureCredentials() GRPC_OVERRIDE { return nullptr; }
+ SecureChannelCredentials* AsSecureCredentials() GRPC_OVERRIDE { return nullptr; }
};
} // namespace
-std::shared_ptr<Credentials> InsecureCredentials() {
- return std::shared_ptr<Credentials>(new InsecureCredentialsImpl());
+std::shared_ptr<ChannelCredentials> InsecureChannelCredentials() {
+ return std::shared_ptr<ChannelCredentials>(
+ new InsecureChannelCredentialsImpl());
}
} // namespace grpc
diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc
index 8299ebeb8a..a1b9a3018e 100644
--- a/src/cpp/client/secure_credentials.cc
+++ b/src/cpp/client/secure_credentials.cc
@@ -40,7 +40,7 @@
namespace grpc {
-std::shared_ptr<grpc::Channel> SecureCredentials::CreateChannel(
+std::shared_ptr<grpc::Channel> SecureChannelCredentials::CreateChannel(
const string& target, const grpc::ChannelArguments& args) {
grpc_channel_args channel_args;
args.SetChannelArgs(&channel_args);
@@ -50,96 +50,104 @@ std::shared_ptr<grpc::Channel> SecureCredentials::CreateChannel(
nullptr));
}
-bool SecureCredentials::ApplyToCall(grpc_call* call) {
+bool SecureCallCredentials::ApplyToCall(grpc_call* call) {
return grpc_call_set_credentials(call, c_creds_) == GRPC_CALL_OK;
}
namespace {
-std::shared_ptr<Credentials> WrapCredentials(grpc_credentials* creds) {
- return creds == nullptr
- ? nullptr
- : std::shared_ptr<Credentials>(new SecureCredentials(creds));
+std::shared_ptr<ChannelCredentials> WrapChannelCredentials(
+ grpc_channel_credentials* creds) {
+ return creds == nullptr ? nullptr : std::shared_ptr<ChannelCredentials>(
+ new SecureChannelCredentials(creds));
+}
+
+std::shared_ptr<CallCredentials> WrapCallCredentials(
+ grpc_call_credentials* creds) {
+ return creds == nullptr ? nullptr : std::shared_ptr<CallCredentials>(
+ new SecureCallCredentials(creds));
}
} // namespace
-std::shared_ptr<Credentials> GoogleDefaultCredentials() {
+std::shared_ptr<ChannelCredentials> GoogleDefaultCredentials() {
GrpcLibrary init; // To call grpc_init().
- return WrapCredentials(grpc_google_default_credentials_create());
+ return WrapChannelCredentials(grpc_google_default_credentials_create());
}
// Builds SSL Credentials given SSL specific options
-std::shared_ptr<Credentials> SslCredentials(
+std::shared_ptr<ChannelCredentials> SslCredentials(
const SslCredentialsOptions& options) {
GrpcLibrary init; // To call grpc_init().
grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {
options.pem_private_key.c_str(), options.pem_cert_chain.c_str()};
- grpc_credentials* c_creds = grpc_ssl_credentials_create(
+ grpc_channel_credentials* c_creds = grpc_ssl_credentials_create(
options.pem_root_certs.empty() ? nullptr : options.pem_root_certs.c_str(),
options.pem_private_key.empty() ? nullptr : &pem_key_cert_pair, nullptr);
- return WrapCredentials(c_creds);
+ return WrapChannelCredentials(c_creds);
}
// Builds credentials for use when running in GCE
-std::shared_ptr<Credentials> GoogleComputeEngineCredentials() {
+std::shared_ptr<CallCredentials> GoogleComputeEngineCredentials() {
GrpcLibrary init; // To call grpc_init().
- return WrapCredentials(
+ return WrapCallCredentials(
grpc_google_compute_engine_credentials_create(nullptr));
}
// Builds JWT credentials.
-std::shared_ptr<Credentials> ServiceAccountJWTAccessCredentials(
+std::shared_ptr<CallCredentials> ServiceAccountJWTAccessCredentials(
const grpc::string& json_key, long token_lifetime_seconds) {
GrpcLibrary init; // To call grpc_init().
if (token_lifetime_seconds <= 0) {
gpr_log(GPR_ERROR,
"Trying to create JWTCredentials with non-positive lifetime");
- return WrapCredentials(nullptr);
+ return WrapCallCredentials(nullptr);
}
gpr_timespec lifetime =
gpr_time_from_seconds(token_lifetime_seconds, GPR_TIMESPAN);
- return WrapCredentials(grpc_service_account_jwt_access_credentials_create(
+ return WrapCallCredentials(grpc_service_account_jwt_access_credentials_create(
json_key.c_str(), lifetime, nullptr));
}
// Builds refresh token credentials.
-std::shared_ptr<Credentials> GoogleRefreshTokenCredentials(
+std::shared_ptr<CallCredentials> GoogleRefreshTokenCredentials(
const grpc::string& json_refresh_token) {
GrpcLibrary init; // To call grpc_init().
- return WrapCredentials(grpc_google_refresh_token_credentials_create(
+ return WrapCallCredentials(grpc_google_refresh_token_credentials_create(
json_refresh_token.c_str(), nullptr));
}
// Builds access token credentials.
-std::shared_ptr<Credentials> AccessTokenCredentials(
+std::shared_ptr<CallCredentials> AccessTokenCredentials(
const grpc::string& access_token) {
GrpcLibrary init; // To call grpc_init().
- return WrapCredentials(
+ return WrapCallCredentials(
grpc_access_token_credentials_create(access_token.c_str(), nullptr));
}
// Builds IAM credentials.
-std::shared_ptr<Credentials> GoogleIAMCredentials(
+std::shared_ptr<CallCredentials> GoogleIAMCredentials(
const grpc::string& authorization_token,
const grpc::string& authority_selector) {
GrpcLibrary init; // To call grpc_init().
- return WrapCredentials(grpc_google_iam_credentials_create(
+ return WrapCallCredentials(grpc_google_iam_credentials_create(
authorization_token.c_str(), authority_selector.c_str(), nullptr));
}
-// Combines two credentials objects into a composite credentials.
-std::shared_ptr<Credentials> CompositeCredentials(
- const std::shared_ptr<Credentials>& creds1,
- const std::shared_ptr<Credentials>& creds2) {
- // Note that we are not saving shared_ptrs to the two credentials
- // passed in here. This is OK because the underlying C objects (i.e.,
- // creds1 and creds2) into grpc_composite_credentials_create will see their
- // refcounts incremented.
- SecureCredentials* s1 = creds1->AsSecureCredentials();
- SecureCredentials* s2 = creds2->AsSecureCredentials();
- if (s1 && s2) {
- return WrapCredentials(grpc_composite_credentials_create(
- s1->GetRawCreds(), s2->GetRawCreds(), nullptr));
+// Combines one channel credentials and one call credentials into a channel
+// composite credentials.
+std::shared_ptr<ChannelCredentials> CompositeChannelCredentials(
+ const std::shared_ptr<ChannelCredentials>& channel_creds,
+ const std::shared_ptr<CallCredentials>& call_creds) {
+ // Note that we are not saving shared_ptrs to the two credentials passed in
+ // here. This is OK because the underlying C objects (i.e., channel_creds and
+ // call_creds) into grpc_composite_credentials_create will see their refcounts
+ // incremented.
+ SecureChannelCredentials* s_channel_creds =
+ channel_creds->AsSecureCredentials();
+ SecureCallCredentials* s_call_creds = call_creds->AsSecureCredentials();
+ if (s_channel_creds && s_call_creds) {
+ return WrapChannelCredentials(grpc_composite_channel_credentials_create(
+ s_channel_creds->GetRawCreds(), s_call_creds->GetRawCreds(), nullptr));
}
return nullptr;
}
@@ -193,7 +201,7 @@ MetadataCredentialsPluginWrapper::MetadataCredentialsPluginWrapper(
std::unique_ptr<MetadataCredentialsPlugin> plugin)
: thread_pool_(CreateDefaultThreadPool()), plugin_(std::move(plugin)) {}
-std::shared_ptr<Credentials> MetadataCredentialsFromPlugin(
+std::shared_ptr<CallCredentials> MetadataCredentialsFromPlugin(
std::unique_ptr<MetadataCredentialsPlugin> plugin) {
GrpcLibrary init; // To call grpc_init().
MetadataCredentialsPluginWrapper* wrapper =
@@ -201,7 +209,7 @@ std::shared_ptr<Credentials> MetadataCredentialsFromPlugin(
grpc_metadata_credentials_plugin c_plugin = {
MetadataCredentialsPluginWrapper::GetMetadata,
MetadataCredentialsPluginWrapper::Destroy, wrapper};
- return WrapCredentials(
+ return WrapCallCredentials(
grpc_metadata_credentials_create_from_plugin(c_plugin, nullptr));
}
diff --git a/src/cpp/client/secure_credentials.h b/src/cpp/client/secure_credentials.h
index d354827725..b241761a7c 100644
--- a/src/cpp/client/secure_credentials.h
+++ b/src/cpp/client/secure_credentials.h
@@ -43,21 +43,40 @@
namespace grpc {
-class SecureCredentials GRPC_FINAL : public Credentials {
+class SecureChannelCredentials GRPC_FINAL : public ChannelCredentials {
public:
- explicit SecureCredentials(grpc_credentials* c_creds) : c_creds_(c_creds) {}
- ~SecureCredentials() GRPC_OVERRIDE { grpc_credentials_release(c_creds_); }
- grpc_credentials* GetRawCreds() { return c_creds_; }
- bool ApplyToCall(grpc_call* call) GRPC_OVERRIDE;
+ explicit SecureChannelCredentials(grpc_channel_credentials* c_creds)
+ : c_creds_(c_creds) {}
+ ~SecureChannelCredentials() GRPC_OVERRIDE {
+ grpc_channel_credentials_release(c_creds_);
+ }
+ grpc_channel_credentials* GetRawCreds() { return c_creds_; }
std::shared_ptr<grpc::Channel> CreateChannel(
const string& target, const grpc::ChannelArguments& args) GRPC_OVERRIDE;
- SecureCredentials* AsSecureCredentials() GRPC_OVERRIDE { return this; }
+ SecureChannelCredentials* AsSecureCredentials() GRPC_OVERRIDE { return this; }
private:
- grpc_credentials* const c_creds_;
+ grpc_channel_credentials* const c_creds_;
};
+class SecureCallCredentials GRPC_FINAL : public CallCredentials {
+ public:
+ explicit SecureCallCredentials(grpc_call_credentials* c_creds)
+ : c_creds_(c_creds) {}
+ ~SecureCallCredentials() GRPC_OVERRIDE {
+ grpc_call_credentials_release(c_creds_);
+ }
+ grpc_call_credentials* GetRawCreds() { return c_creds_; }
+
+ bool ApplyToCall(grpc_call* call) GRPC_OVERRIDE;
+ SecureCallCredentials* AsSecureCredentials() GRPC_OVERRIDE { return this; }
+
+ private:
+ grpc_call_credentials* const c_creds_;
+};
+
+
class MetadataCredentialsPluginWrapper GRPC_FINAL {
public:
static void Destroy(void* wrapper);