Skip to content

feat(generator): support x-goog-user-project#8245

Merged
coryan merged 3 commits into
googleapis:mainfrom
coryan:feat-generator-support-x-goog-user-project
Feb 7, 2022
Merged

feat(generator): support x-goog-user-project#8245
coryan merged 3 commits into
googleapis:mainfrom
coryan:feat-generator-support-x-goog-user-project

Conversation

@coryan
Copy link
Copy Markdown
Contributor

@coryan coryan commented Feb 4, 2022

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 Reviewable

@google-cloud-cpp-bot
Copy link
Copy Markdown
Contributor

Google Cloud Build Logs
For commit: 745388922619d1601aee8bb78e3b52df781cb312

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 4, 2022

Codecov Report

Merging #8245 (f673d77) into main (b0445f0) will increase coverage by 0.00%.
The diff coverage is 97.10%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #8245   +/-   ##
=======================================
  Coverage   94.94%   94.95%           
=======================================
  Files        1335     1335           
  Lines      119241   119306   +65     
=======================================
+ Hits       113219   113282   +63     
- Misses       6022     6024    +2     
Impacted Files Coverage Δ
generator/internal/metadata_decorator_generator.cc 59.37% <ø> (ø)
generator/internal/option_defaults_generator.cc 100.00% <ø> (ø)
.../internal/golden_thing_admin_metadata_decorator.cc 97.53% <50.00%> (-2.47%) ⬇️
...internal/golden_kitchen_sink_metadata_decorator.cc 85.71% <100.00%> (+1.50%) ⬆️
...en/internal/golden_kitchen_sink_option_defaults.cc 94.11% <100.00%> (+1.01%) ⬆️
...den/internal/golden_thing_admin_option_defaults.cc 95.00% <100.00%> (+0.71%) ⬆️
...sts/golden_kitchen_sink_metadata_decorator_test.cc 100.00% <100.00%> (ø)
.../tests/golden_kitchen_sink_option_defaults_test.cc 100.00% <100.00%> (ø)
...le/cloud/storage/internal/curl_download_request.cc 89.75% <0.00%> (-0.36%) ⬇️
google/cloud/pubsub/samples/samples.cc 92.10% <0.00%> (-0.24%) ⬇️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b0445f0...f673d77. Read the comment docs.

@coryan coryan marked this pull request as ready for review February 4, 2022 19:36
@coryan coryan requested a review from a team February 4, 2022 19:36
@coryan coryan enabled auto-merge (squash) February 4, 2022 20:32
@coryan coryan disabled auto-merge February 4, 2022 21:08
@coryan coryan mentioned this pull request Feb 5, 2022
31 tasks
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.
@coryan coryan force-pushed the feat-generator-support-x-goog-user-project branch from 7453889 to f673d77 Compare February 7, 2022 12:47
@google-cloud-cpp-bot
Copy link
Copy Markdown
Contributor

Google Cloud Build Logs
For commit: f673d77f87f382d18bc5cc0f11d3439b82aa94fd

ℹ️ NOTE: Kokoro logs are linked from "Details" below.

@coryan coryan enabled auto-merge (squash) February 7, 2022 14:35
@coryan coryan merged commit be01a2b into googleapis:main Feb 7, 2022
@coryan coryan deleted the feat-generator-support-x-goog-user-project branch February 7, 2022 17:13
Comment on lines +100 to +104
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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably use either env or env.has_value() consistently when they're this close together.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. I will send a PR to clean this up, I think there is some opportunity for refactoring too.

Comment on lines +102 to +105
if (!options.has<UserProjectOption>()) {
auto env = internal::GetEnv("GOOGLE_CLOUD_CPP_USER_PROJECT");
if (env.has_value() && !env->empty()) options.set<UserProjectOption>(*env);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be adding this to the non-generated default options?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I am planning to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants