fix(client): For ADC, send x-goog-user-project header#215
fix(client): For ADC, send x-goog-user-project header#215jpoehnelt merged 2 commits intogoogleworkspace:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 39fcea5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue where the 'gws' client failed to send the 'x-goog-user-project' header when using Application Default Credentials (ADC) with a specified 'quota_project_id'. By integrating a mechanism to parse the 'quota_project_id' directly from the ADC file and automatically attaching it as an 'x-goog-user-project' header to all outgoing HTTP requests, this change ensures proper billing and quota attribution, resolving 403 access errors for users relying on ADC. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request correctly identifies and addresses an issue where the quota_project_id from Application Default Credentials (ADC) was not being sent. The approach of adding the x-goog-user-project header in build_client() is sound. However, the implementation for retrieving the ADC file path in get_quota_project is incomplete, as it only checks the well-known path and neglects the GOOGLE_APPLICATION_CREDENTIALS environment variable, which takes precedence. I've provided a detailed comment on how to rectify this to ensure complete ADC support.
When using Application Default Credentials with a quota_project_id set, API requests failed with 403 because the quota project header was never sent. Read quota_project_id from ADC and set it as a default header.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request aims to fix an issue where the x-goog-user-project header was not being sent when using Application Default Credentials (ADC), by reading the quota_project_id from the ADC file. The implementation correctly adds the header in src/client.rs. However, the logic for finding the ADC file in src/auth.rs is incomplete, as it only checks the well-known path and ignores the GOOGLE_APPLICATION_CREDENTIALS environment variable. I've provided a critical feedback to address this correctness issue.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #215 +/- ##
==========================================
+ Coverage 56.99% 57.58% +0.59%
==========================================
Files 38 38
Lines 14079 14211 +132
==========================================
+ Hits 8024 8184 +160
+ Misses 6055 6027 -28 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
When using ADC,
gwsreads the credentials file but ignores thequota_project_idfield. This means thex-goog-user-projectheader is never sent.This fix reads
quota_project_idfrom the ADC file and sets it as a defaultx-goog-user-projectheader on all HTTP requests viabuild_client().Before:
gws drive files listfails with 403 when using ADC with a quota project set.{ "error": { "code": 403, "message": "Your application is authenticating by using local Application Default Credentials. The drive.googleapis.com API requires a quota project, which is not set by default. To learn how to set your quota project, see https://cloud.google.com/docs/authentication/adc-troubleshooting/user-creds .", "reason": "accessNotConfigured" } }After: The quota project header is sent automatically and the request succeeds.
Checklist:
AGENTS.mdguidelines (no generatedgoogle-*crates).cargo fmt --allto format the code perfectly.cargo clippy -- -D warningsand resolved all warnings.pnpx changeset) to document my changes.