aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp
diff options
context:
space:
mode:
authorGravatar Yang Gao <yangg@google.com>2015-03-12 23:41:46 -0700
committerGravatar Yang Gao <yangg@google.com>2015-03-12 23:41:46 -0700
commit05e3eefcf853c870b5273021ca79adeadbb1683a (patch)
tree0f3d7c299efe7eb60e0807e37328ad35eaaa36c6 /src/cpp
parentd778651c0147393eee2e41de0ac86322473c4186 (diff)
Early return when duration is non-positive
Diffstat (limited to 'src/cpp')
-rw-r--r--src/cpp/client/secure_credentials.cc12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc
index 795d7731c9..fa5ce1e5d4 100644
--- a/src/cpp/client/secure_credentials.cc
+++ b/src/cpp/client/secure_credentials.cc
@@ -98,8 +98,10 @@ std::unique_ptr<Credentials> ComputeEngineCredentials() {
std::unique_ptr<Credentials> ServiceAccountCredentials(
const grpc::string& json_key, const grpc::string& scope,
std::chrono::seconds token_lifetime) {
- gpr_timespec lifetime = gpr_time_from_seconds(
- token_lifetime.count() > 0 ? token_lifetime.count() : 0);
+ if (token_lifetime.count() <= 0) {
+ return WrapCredentials(nullptr);
+ }
+ gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime.count());
return WrapCredentials(grpc_service_account_credentials_create(
json_key.c_str(), scope.c_str(), lifetime));
}
@@ -107,8 +109,10 @@ std::unique_ptr<Credentials> ServiceAccountCredentials(
// Builds JWT credentials.
std::unique_ptr<Credentials> 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);
+ if (token_lifetime.count() <= 0) {
+ return WrapCredentials(nullptr);
+ }
+ gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime.count());
return WrapCredentials(
grpc_jwt_credentials_create(json_key.c_str(), lifetime));
}