Skip to content

Commit f553bde

Browse files
feat: add documentation and automation for GCP project recreation (gemini-cli-extensions#165)
* feat: add documentation and automation for GCP project recreation - Add docs/GCP-RECREATION.md with step-by-step setup guide - Add scripts/setup-gcp.sh to automate API enablement and infrastructure deployment - Refactor AuthManager to support configurable CLIENT_ID and CLOUD_FUNCTION_URL via environment variables - Update README.md with deployment section * Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * style: fix prettier formatting in docs * Update scripts/setup-gcp.sh Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * fix: restructure setup-gcp.sh to eliminate circular dependency Reorder the script to deploy the Cloud Function first, then prompt the user to create OAuth credentials using the deployed URL. This fixes the chicken-and-egg problem identified in code review. Update GCP-RECREATION.md to match the new linear flow. * Update scripts/setup-gcp.sh Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * fix: resolve setup script issues found during end-to-end testing - Move env var validation from module-load to request-time in cloud function so initial deploy (without OAuth config) can start - Fix trailing newline in stored secret (echo -> echo -n) that caused invalid_client errors during token exchange - Add run.googleapis.com and artifactregistry.googleapis.com APIs required by gen2 Cloud Functions - Make script idempotent: skip initial deploy if function already exists - Integrate OAuth consent screen setup into script flow with browser auto-open, scopes list, and test users reminder - Open Credentials page in browser during OAuth client step - Upgrade Cloud Function runtime from nodejs20 to nodejs22 - Generate package-lock.json for cloud function * style: fix prettier formatting in cloud function * chore: update copyright year to 2026 * Updating lint config to support both 2025 and 2026 years in the license header. * Updating deps for new eslint-plugin-headers package. * format fix --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent ceb5cf4 commit f553bde

11 files changed

Lines changed: 3219 additions & 35 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ Shows your schedule for today or a specified date.
5454

5555
Searches your Google Drive for files matching the given query.
5656

57+
## Deployment
58+
59+
If you want to host your own version of this extension's infrastructure, see the
60+
[GCP Recreation Guide](docs/GCP-RECREATION.md).
61+
5762
## Resources
5863

5964
- [Documentation](docs/index.md): Detailed documentation on all the available

cloud_function/index.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,13 @@ const axios = require('axios');
1111
const { URL } = require('node:url');
1212

1313
// --- Configuration loaded from Environment Variables ---
14-
// These are set in the Google Cloud Function's configuration
14+
// These are set in the Google Cloud Function's configuration.
15+
// They may be absent on the initial deploy (before OAuth credentials exist)
16+
// and are set on the final deploy. Validation happens at request time.
1517
const CLIENT_ID = process.env.CLIENT_ID;
1618
const SECRET_NAME = process.env.SECRET_NAME;
1719
const REDIRECT_URI = process.env.REDIRECT_URI;
1820

19-
// Fail fast if required environment variables are missing
20-
if (!CLIENT_ID || !SECRET_NAME || !REDIRECT_URI) {
21-
throw new Error(
22-
'Missing required environment variables: CLIENT_ID, SECRET_NAME, and REDIRECT_URI must be set.',
23-
);
24-
}
25-
2621
// --- Configuration for local storage (used in instructions) ---
2722
const KEYCHAIN_SERVICE_NAME = 'gemini-cli-workspace-oauth';
2823
const KEYCHAIN_ACCOUNT_NAME = 'main-account';
@@ -340,6 +335,15 @@ async function handleRefreshToken(req, res) {
340335
* Routes requests to either the callback handler or the refresh handler.
341336
*/
342337
functions.http('oauthHandler', async (req, res) => {
338+
// Validate required environment variables at request time
339+
if (!CLIENT_ID || !SECRET_NAME || !REDIRECT_URI) {
340+
return res
341+
.status(503)
342+
.send(
343+
'Function not yet configured. Missing required environment variables: CLIENT_ID, SECRET_NAME, REDIRECT_URI.',
344+
);
345+
}
346+
343347
// Route to refresh handler if path ends with /refresh or /refreshToken or it's a POST with refresh_token
344348
if (
345349
['/refresh', '/refreshToken'].includes(req.path) ||

0 commit comments

Comments
 (0)