Skip to content

fix(client): For ADC, send x-goog-user-project header#215

Merged
jpoehnelt merged 2 commits intogoogleworkspace:mainfrom
AdeelK93:main
Mar 5, 2026
Merged

fix(client): For ADC, send x-goog-user-project header#215
jpoehnelt merged 2 commits intogoogleworkspace:mainfrom
AdeelK93:main

Conversation

@AdeelK93
Copy link
Contributor

@AdeelK93 AdeelK93 commented Mar 5, 2026

Description

When using ADC, gws reads the credentials file but ignores the quota_project_id field. This means the x-goog-user-project header is never sent.

This fix reads quota_project_id from the ADC file and sets it as a default x-goog-user-project header on all HTTP requests via build_client().

Before: gws drive files list fails 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:

  • My code follows the AGENTS.md guidelines (no generated google-* crates).
  • I have run cargo fmt --all to format the code perfectly.
  • I have run cargo clippy -- -D warnings and resolved all warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have provided a Changeset file (e.g. via pnpx changeset) to document my changes.

@AdeelK93 AdeelK93 requested a review from jpoehnelt as a code owner March 5, 2026 22:17
@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

🦋 Changeset detected

Latest commit: 39fcea5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • ADC Quota Project Handling: Implemented logic to read the 'quota_project_id' from the Application Default Credentials (ADC) file.
  • HTTP Header Injection: Configured the HTTP client to automatically include the 'x-goog-user-project' header with the retrieved 'quota_project_id' for all requests.
  • Bug Fix: Resolved a 403 error encountered when using ADC with a quota project, ensuring API requests succeed without manual header configuration.
Changelog
  • .changeset/fix-adc-quota-project.md
    • Send x-goog-user-project header when using ADC with a quota_project_id
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@google-cla
Copy link

google-cla bot commented Mar 5, 2026

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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.
@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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>
@jpoehnelt jpoehnelt merged commit 2173a92 into googleworkspace:main Mar 5, 2026
31 of 33 checks passed
@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

❌ Patch coverage is 89.65517% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.58%. Comparing base (3d59b2e) to head (39fcea5).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
src/client.rs 40.00% 3 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants