feat: add GWS_API_BASE_URL for custom/mock endpoint support#97
feat: add GWS_API_BASE_URL for custom/mock endpoint support#97xdotli wants to merge 2 commits intogoogleworkspace:mainfrom
Conversation
When GWS_API_BASE_URL is set (e.g., http://localhost:8099), all API requests are redirected to the custom endpoint and OAuth authentication is skipped automatically. The real Discovery Document is still fetched so the CLI command tree remains fully functional — only root_url and base_url are rewritten to point at the custom endpoint. This enables testing against mock API servers without any code changes to agents or skills. Similar to gog CLI's GOG_ENDPOINT pattern. Changes: - discovery.rs: add custom_api_base_url() helper; rewrite doc URLs when env var is set - executor.rs: add resolve_auth() that skips OAuth for custom endpoints - main.rs, mcp_server.rs: use resolve_auth() for consistent behavior Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
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 enhances the 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 introduces a GWS_API_BASE_URL environment variable to support custom API endpoints, which is a great feature for testing against mock servers. The implementation is solid: it correctly rewrites discovery document URLs, skips authentication for custom endpoints, and centralizes the new logic in helper functions for better maintainability. The changes are consistently applied across both CLI and MCP server modes. I have one suggestion to further improve the implementation by reading the environment variable only once.
| /// Returns the custom API base URL override, if set. | ||
| /// | ||
| /// When `GWS_API_BASE_URL` is set (e.g., `http://localhost:8099`), all API | ||
| /// requests are directed to this endpoint instead of the real Google APIs. | ||
| /// Authentication is skipped automatically. This is useful for testing against | ||
| /// mock API servers. | ||
| pub fn custom_api_base_url() -> Option<String> { | ||
| std::env::var("GWS_API_BASE_URL").ok().filter(|s| !s.is_empty()) | ||
| } |
There was a problem hiding this comment.
For better performance and to ensure consistency, it's a good practice to read the GWS_API_BASE_URL environment variable only once. You can use the once_cell crate to achieve this with a Lazy static. This avoids repeated environment variable lookups on every call.
You'll need to add once_cell = "1" to your Cargo.toml dependencies.
| /// Returns the custom API base URL override, if set. | |
| /// | |
| /// When `GWS_API_BASE_URL` is set (e.g., `http://localhost:8099`), all API | |
| /// requests are directed to this endpoint instead of the real Google APIs. | |
| /// Authentication is skipped automatically. This is useful for testing against | |
| /// mock API servers. | |
| pub fn custom_api_base_url() -> Option<String> { | |
| std::env::var("GWS_API_BASE_URL").ok().filter(|s| !s.is_empty()) | |
| } | |
| use once_cell::sync::Lazy; // Add to file imports | |
| static GWS_API_BASE_URL: Lazy<Option<String>> = | |
| Lazy::new(|| std::env::var("GWS_API_BASE_URL").ok().filter(|s| !s.is_empty())); | |
| /// Returns the custom API base URL override, if set. | |
| /// | |
| /// When `GWS_API_BASE_URL` is set (e.g., `http://localhost:8099`), all API | |
| /// requests are directed to this endpoint instead of the real Google APIs. | |
| /// Authentication is skipped automatically. This is useful for testing against | |
| /// mock API servers. | |
| pub fn custom_api_base_url() -> Option<String> { | |
| GWS_API_BASE_URL.as_ref().cloned() | |
| } |
Read the environment variable once at startup instead of on every call. Uses std::sync::LazyLock (stable since Rust 1.80) — no external crate needed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
Adds a
GWS_API_BASE_URLenvironment variable that redirects all API requests to a custom endpoint (e.g., a mock server). When set:root_urlandbase_urlin the Discovery Document are rewritten to the custom endpointMotivation
Testing agents and skills against mock API servers is a common need for development and CI. The
gogCLI already supports this viaGOG_ENDPOINT. This PR brings the same capability togws.Example usage
Changes
src/discovery.rs: Addcustom_api_base_url()helper; rewrite Discovery Document URLs when env var is setsrc/executor.rs: Addresolve_auth()that skips OAuth for custom endpointssrc/main.rs,src/mcp_server.rs: Useresolve_auth()for consistent behaviorTest plan
cargo checkpasses🤖 Generated with Claude Code