diff options
author | Julien Boeuf <jboeuf@google.com> | 2015-02-23 13:00:36 -0800 |
---|---|---|
committer | Julien Boeuf <jboeuf@google.com> | 2015-02-23 13:00:36 -0800 |
commit | c66f2a816e02b55c82679f5ae6ae29d37991b786 (patch) | |
tree | 70b6703f61187485a3815465eb50de70963829f2 /src | |
parent | cd9b1c850db35ad37669dc0a650712b1cd29527f (diff) |
Addressing iniitial feedback.
- Renaming default credentials -> google default credentials.
- Various other things in cpp:
- Adding Cpp wrapping for JWT Tokens.
- Renaming ComposeCredentials -> CompositeCredentials.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/security/credentials.h | 2 | ||||
-rw-r--r-- | src/core/security/credentials_posix.c | 2 | ||||
-rw-r--r-- | src/core/security/credentials_win32.c | 2 | ||||
-rw-r--r-- | src/core/security/google_default_credentials.c (renamed from src/core/security/default_credentials.c) | 4 | ||||
-rw-r--r-- | src/core/security/security_context.c | 6 | ||||
-rw-r--r-- | src/cpp/client/credentials.cc | 18 |
6 files changed, 20 insertions, 14 deletions
diff --git a/src/core/security/credentials.h b/src/core/security/credentials.h index 9886afc9c0..0a0074c1d5 100644 --- a/src/core/security/credentials.h +++ b/src/core/security/credentials.h @@ -67,7 +67,7 @@ typedef enum { /* --- grpc_credentials. --- */ /* It is the caller's responsibility to gpr_free the result if not NULL. */ -char *grpc_get_well_known_credentials_file_path(void); +char *grpc_get_well_known_google_credentials_file_path(void); typedef void (*grpc_credentials_metadata_cb)(void *user_data, grpc_mdelem **md_elems, diff --git a/src/core/security/credentials_posix.c b/src/core/security/credentials_posix.c index 9cffd64d31..79622cb024 100644 --- a/src/core/security/credentials_posix.c +++ b/src/core/security/credentials_posix.c @@ -43,7 +43,7 @@ #include "src/core/support/env.h" #include "src/core/support/string.h" -char *grpc_get_well_known_credentials_file_path(void) { +char *grpc_get_well_known_google_credentials_file_path(void) { char *result = NULL; char *home = gpr_getenv("HOME"); if (home == NULL) { diff --git a/src/core/security/credentials_win32.c b/src/core/security/credentials_win32.c index a8b711517b..ddb310468b 100644 --- a/src/core/security/credentials_win32.c +++ b/src/core/security/credentials_win32.c @@ -43,7 +43,7 @@ #include "src/core/support/env.h" #include "src/core/support/string.h" -char *grpc_get_well_known_credentials_file_path(void) { +char *grpc_get_well_known_google_credentials_file_path(void) { char *result = NULL; char *appdata_path = gpr_getenv("APPDATA"); if (appdata_path == NULL) { diff --git a/src/core/security/default_credentials.c b/src/core/security/google_default_credentials.c index d7a974d8a1..dc0e453b87 100644 --- a/src/core/security/default_credentials.c +++ b/src/core/security/google_default_credentials.c @@ -138,7 +138,7 @@ static grpc_credentials *create_jwt_creds_from_path(char *creds_path) { return result; } -grpc_credentials *grpc_default_credentials_create(void) { +grpc_credentials *grpc_google_default_credentials_create(void) { grpc_credentials *result = NULL; int serving_cached_credentials = 0; gpr_once_init(&g_once, init_default_credentials); @@ -158,7 +158,7 @@ grpc_credentials *grpc_default_credentials_create(void) { /* Then the well-known file. */ result = create_jwt_creds_from_path( - grpc_get_well_known_credentials_file_path()); + grpc_get_well_known_google_credentials_file_path()); if (result != NULL) goto end; /* At last try to see if we're on compute engine (do the detection only once diff --git a/src/core/security/security_context.c b/src/core/security/security_context.c index 71bd06b271..df6728ca4b 100644 --- a/src/core/security/security_context.c +++ b/src/core/security/security_context.c @@ -636,9 +636,3 @@ grpc_channel *grpc_secure_channel_create_with_factories( creds->type); return grpc_lame_client_channel_create(); } - -grpc_channel *grpc_default_secure_channel_create( - const char *target, const grpc_channel_args *args) { - return grpc_secure_channel_create(grpc_default_credentials_create(), target, - args); -} 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<Credentials> CredentialsFactory::DefaultCredentials() { - grpc_credentials *c_creds = grpc_default_credentials_create(); +std::unique_ptr<Credentials> CredentialsFactory::GoogleDefaultCredentials() { + grpc_credentials *c_creds = grpc_google_default_credentials_create(); std::unique_ptr<Credentials> cpp_creds(new Credentials(c_creds)); return cpp_creds; } @@ -86,6 +86,18 @@ std::unique_ptr<Credentials> CredentialsFactory::ServiceAccountCredentials( return cpp_creds; } +// Builds JWT credentials. +std::unique_ptr<Credentials> 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<Credentials> cpp_creds( + c_creds == nullptr ? nullptr : new Credentials(c_creds)); + return cpp_creds; +} + // Builds IAM credentials. std::unique_ptr<Credentials> CredentialsFactory::IAMCredentials( const grpc::string &authorization_token, @@ -98,7 +110,7 @@ std::unique_ptr<Credentials> CredentialsFactory::IAMCredentials( } // Combines two credentials objects into a composite credentials. -std::unique_ptr<Credentials> CredentialsFactory::ComposeCredentials( +std::unique_ptr<Credentials> CredentialsFactory::CompositeCredentials( const std::unique_ptr<Credentials> &creds1, const std::unique_ptr<Credentials> &creds2) { // Note that we are not saving unique_ptrs to the two credentials |