feat(generator): support x-goog-user-project#8245
Conversation
|
Google Cloud Build Logs
ℹ️ NOTE: Kokoro logs are linked from "Details" below. |
Codecov Report
@@ Coverage Diff @@
## main #8245 +/- ##
=======================================
Coverage 94.94% 94.95%
=======================================
Files 1335 1335
Lines 119241 119306 +65
=======================================
+ Hits 113219 113282 +63
- Misses 6022 6024 +2
Continue to review full report at Codecov.
|
Many services cannot be used directly from a user account. User accounts have no default project associated with them for quota and billing, and some services do not have any resources attached to a specific project either. For example, compute-only services like Text-to-Speech. In this case the recommendation is to use the x-goog-user-project header, or use service account impersonation. The latter is fairly difficult, and would make the "quickstart" not very quick. This PR introduces a new option to configure this header. The default comes from an environment variable.
7453889 to
f673d77
Compare
|
Google Cloud Build Logs
ℹ️ NOTE: Kokoro logs are linked from "Details" below. |
| env && !env->empty() ? *env : "$service_endpoint$"); | ||
| } | ||
| if (!options.has<UserProjectOption>()) { | ||
| auto env = internal::GetEnv("GOOGLE_CLOUD_CPP_USER_PROJECT"); | ||
| if (env.has_value() && !env->empty()) options.set<UserProjectOption>(*env); |
There was a problem hiding this comment.
We should probably use either env or env.has_value() consistently when they're this close together.
There was a problem hiding this comment.
Ack. I will send a PR to clean this up, I think there is some opportunity for refactoring too.
| if (!options.has<UserProjectOption>()) { | ||
| auto env = internal::GetEnv("GOOGLE_CLOUD_CPP_USER_PROJECT"); | ||
| if (env.has_value() && !env->empty()) options.set<UserProjectOption>(*env); | ||
| } |
There was a problem hiding this comment.
Should we be adding this to the non-generated default options?
There was a problem hiding this comment.
Yes. I am planning to do that.
Many services cannot be used directly from a user account. User accounts
have no default project associated with them for quota and billing, and
some services do not have any resources attached to a specific project
either. For example, compute-only services like Text-to-Speech. In this
case the recommendation is to use the x-goog-user-project header, or use
service account impersonation. The latter is fairly difficult, and would
make the "quickstart" not very quick.
This PR introduces a new option to configure this header. The default
comes from an environment variable.
Part of the work for #7936, or at least motivated by it.
This change is