summaryrefslogtreecommitdiff
path: root/packages/cli/src/validateNonInterActiveAuth.ts
diff options
context:
space:
mode:
authorJerop Kipruto <[email protected]>2025-07-22 10:52:40 -0400
committerGitHub <[email protected]>2025-07-22 14:52:40 +0000
commite306b34a6ea4f3ec5fcdf410738d6316c3c5d655 (patch)
tree9557daa6b012621eeac37707851768cdbac41c2e /packages/cli/src/validateNonInterActiveAuth.ts
parent4d653c833ac1371939876e03407471248263393e (diff)
feat(auth): support gemini api key and vertex auth in non-interactive mode (#4631)
Diffstat (limited to 'packages/cli/src/validateNonInterActiveAuth.ts')
-rw-r--r--packages/cli/src/validateNonInterActiveAuth.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/packages/cli/src/validateNonInterActiveAuth.ts b/packages/cli/src/validateNonInterActiveAuth.ts
new file mode 100644
index 00000000..87a7f4ff
--- /dev/null
+++ b/packages/cli/src/validateNonInterActiveAuth.ts
@@ -0,0 +1,38 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { AuthType, Config } from '@google/gemini-cli-core';
+import { USER_SETTINGS_PATH } from './config/settings.js';
+import { validateAuthMethod } from './config/auth.js';
+
+export async function validateNonInteractiveAuth(
+ configuredAuthType: AuthType | undefined,
+ nonInteractiveConfig: Config,
+) {
+ const effectiveAuthType =
+ configuredAuthType ||
+ (process.env.GOOGLE_GENAI_USE_VERTEXAI === 'true'
+ ? AuthType.USE_VERTEX_AI
+ : process.env.GEMINI_API_KEY
+ ? AuthType.USE_GEMINI
+ : undefined);
+
+ if (!effectiveAuthType) {
+ console.error(
+ `Please set an Auth method in your ${USER_SETTINGS_PATH} or specify either the GEMINI_API_KEY or GOOGLE_GENAI_USE_VERTEXAI environment variables before running`,
+ );
+ process.exit(1);
+ }
+
+ const err = validateAuthMethod(effectiveAuthType);
+ if (err != null) {
+ console.error(err);
+ process.exit(1);
+ }
+
+ await nonInteractiveConfig.refreshAuth(effectiveAuthType);
+ return nonInteractiveConfig;
+}