|
|
@ -98,8 +98,10 @@ std::unique_ptr<Credentials> ComputeEngineCredentials() { |
|
|
|
std::unique_ptr<Credentials> ServiceAccountCredentials( |
|
|
|
std::unique_ptr<Credentials> ServiceAccountCredentials( |
|
|
|
const grpc::string& json_key, const grpc::string& scope, |
|
|
|
const grpc::string& json_key, const grpc::string& scope, |
|
|
|
std::chrono::seconds token_lifetime) { |
|
|
|
std::chrono::seconds token_lifetime) { |
|
|
|
gpr_timespec lifetime = gpr_time_from_seconds( |
|
|
|
if (token_lifetime.count() <= 0) { |
|
|
|
token_lifetime.count() > 0 ? token_lifetime.count() : 0); |
|
|
|
return WrapCredentials(nullptr); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime.count()); |
|
|
|
return WrapCredentials(grpc_service_account_credentials_create( |
|
|
|
return WrapCredentials(grpc_service_account_credentials_create( |
|
|
|
json_key.c_str(), scope.c_str(), lifetime)); |
|
|
|
json_key.c_str(), scope.c_str(), lifetime)); |
|
|
|
} |
|
|
|
} |
|
|
@ -107,8 +109,10 @@ std::unique_ptr<Credentials> ServiceAccountCredentials( |
|
|
|
// Builds JWT credentials.
|
|
|
|
// Builds JWT credentials.
|
|
|
|
std::unique_ptr<Credentials> JWTCredentials( |
|
|
|
std::unique_ptr<Credentials> JWTCredentials( |
|
|
|
const grpc::string &json_key, std::chrono::seconds token_lifetime) { |
|
|
|
const grpc::string &json_key, std::chrono::seconds token_lifetime) { |
|
|
|
gpr_timespec lifetime = gpr_time_from_seconds( |
|
|
|
if (token_lifetime.count() <= 0) { |
|
|
|
token_lifetime.count() > 0 ? token_lifetime.count() : 0); |
|
|
|
return WrapCredentials(nullptr); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
gpr_timespec lifetime = gpr_time_from_seconds(token_lifetime.count()); |
|
|
|
return WrapCredentials( |
|
|
|
return WrapCredentials( |
|
|
|
grpc_jwt_credentials_create(json_key.c_str(), lifetime)); |
|
|
|
grpc_jwt_credentials_create(json_key.c_str(), lifetime)); |
|
|
|
} |
|
|
|
} |
|
|
|