From c66f2a816e02b55c82679f5ae6ae29d37991b786 Mon Sep 17 00:00:00 2001 From: Julien Boeuf Date: Mon, 23 Feb 2015 13:00:36 -0800 Subject: Addressing iniitial feedback. - Renaming default credentials -> google default credentials. - Various other things in cpp: - Adding Cpp wrapping for JWT Tokens. - Renaming ComposeCredentials -> CompositeCredentials. --- src/cpp/client/credentials.cc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/cpp/client') diff --git a/src/cpp/client/credentials.cc b/src/cpp/client/credentials.cc index 66571cad73..a140f551e0 100644 --- a/src/cpp/client/credentials.cc +++ b/src/cpp/client/credentials.cc @@ -45,8 +45,8 @@ Credentials::Credentials(grpc_credentials *c_creds) : creds_(c_creds) {} Credentials::~Credentials() { grpc_credentials_release(creds_); } grpc_credentials *Credentials::GetRawCreds() { return creds_; } -std::unique_ptr CredentialsFactory::DefaultCredentials() { - grpc_credentials *c_creds = grpc_default_credentials_create(); +std::unique_ptr CredentialsFactory::GoogleDefaultCredentials() { + grpc_credentials *c_creds = grpc_google_default_credentials_create(); std::unique_ptr cpp_creds(new Credentials(c_creds)); return cpp_creds; } @@ -86,6 +86,18 @@ std::unique_ptr CredentialsFactory::ServiceAccountCredentials( return cpp_creds; } +// Builds JWT credentials. +std::unique_ptr CredentialsFactory::JWTCredentials( + const grpc::string &json_key, std::chrono::seconds token_lifetime) { + gpr_timespec lifetime = gpr_time_from_seconds( + token_lifetime.count() > 0 ? token_lifetime.count() : 0); + grpc_credentials *c_creds = + grpc_jwt_credentials_create(json_key.c_str(), lifetime); + std::unique_ptr cpp_creds( + c_creds == nullptr ? nullptr : new Credentials(c_creds)); + return cpp_creds; +} + // Builds IAM credentials. std::unique_ptr CredentialsFactory::IAMCredentials( const grpc::string &authorization_token, @@ -98,7 +110,7 @@ std::unique_ptr CredentialsFactory::IAMCredentials( } // Combines two credentials objects into a composite credentials. -std::unique_ptr CredentialsFactory::ComposeCredentials( +std::unique_ptr CredentialsFactory::CompositeCredentials( const std::unique_ptr &creds1, const std::unique_ptr &creds2) { // Note that we are not saving unique_ptrs to the two credentials -- cgit v1.2.3