fix(client): Move x-goog-user-project header to API requests only#242
fix(client): Move x-goog-user-project header to API requests only#242jpoehnelt merged 1 commit intogoogleworkspace:mainfrom
Conversation
🦋 Changeset detectedLatest commit: ce4436a 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 resolves a critical regression that caused Google API Discovery Document fetches to fail with 403 errors due to the x-goog-user-project header being prematurely applied. By moving this header to be included only during the construction of actual API requests, the system now correctly distinguishes between discovery and API calls, preventing erroneous discovery failures and providing clearer, more actionable error messages for genuine authentication issues. Highlights
Changelog
Activity
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
|
There was a problem hiding this comment.
Code Review
This pull request correctly moves the x-goog-user-project header from the default client to the API request builder, which resolves the issue with Discovery Document fetches failing for certain projects. The logic seems sound. However, I've identified a potential panic in the new implementation in executor.rs if the quota_project_id from the ADC file contains invalid characters for an HTTP header. I've suggested a change to handle this gracefully by returning an error instead of crashing.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #242 +/- ##
==========================================
+ Coverage 57.69% 57.70% +0.01%
==========================================
Files 38 38
Lines 14328 14327 -1
==========================================
+ Hits 8267 8268 +1
+ Misses 6061 6059 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
Apologies - I believe I introduced a narrow regression in #215.
I had added
x-goog-user-projectheader was added tobuild_client()headers. However, sincebuild_client()is shared by both API calls and Discovery Document fetches, services whose APIs aren't enabled on the quota project fail at discovery with403 Forbidden.This fix moves the header from
build_client()tobuild_http_request()inexecutor.rs.Before:
gws gmail users messages list --params '{"userId":"me"}'{ "error": { "code": 500, "message": "Failed to fetch Discovery Document for gmail/v1: HTTP 403 Forbidden (tried both standard and $discovery URLs)", "reason": "discoveryError" } }After:
{ "error": { "code": 403, "message": "Request had insufficient authentication scopes.", "reason": "insufficientPermissions" } }Discovery succeeds and now you get a more meaningful auth scope issue, rather than a discovery failure.
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.