2025-06-19 16:52:22 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-06-25 05:41:11 -07:00
|
|
|
import { AuthType } from '@google/gemini-cli-core';
|
2025-08-28 13:52:25 -04:00
|
|
|
import { loadEnvironment, loadSettings } from './settings.js';
|
2025-06-19 16:52:22 -07:00
|
|
|
|
2025-08-28 13:52:25 -04:00
|
|
|
export function validateAuthMethod(authMethod: string): string | null {
|
2026-02-03 00:54:10 -05:00
|
|
|
loadEnvironment(loadSettings().merged, process.cwd());
|
2025-07-07 15:52:04 -07:00
|
|
|
if (
|
|
|
|
|
authMethod === AuthType.LOGIN_WITH_GOOGLE ||
|
2025-11-14 11:39:11 -05:00
|
|
|
authMethod === AuthType.COMPUTE_ADC
|
2025-07-07 15:52:04 -07:00
|
|
|
) {
|
2025-06-19 16:52:22 -07:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (authMethod === AuthType.USE_GEMINI) {
|
2025-11-20 20:57:59 -08:00
|
|
|
if (!process.env['GEMINI_API_KEY']) {
|
|
|
|
|
return (
|
|
|
|
|
'When using Gemini API, you must specify the GEMINI_API_KEY environment variable.\n' +
|
|
|
|
|
'Update your environment and try again (no reload needed if using .env)!'
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-06-19 16:52:22 -07:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (authMethod === AuthType.USE_VERTEX_AI) {
|
2025-06-22 17:30:58 -07:00
|
|
|
const hasVertexProjectLocationConfig =
|
2025-08-17 12:43:21 -04:00
|
|
|
!!process.env['GOOGLE_CLOUD_PROJECT'] &&
|
|
|
|
|
!!process.env['GOOGLE_CLOUD_LOCATION'];
|
|
|
|
|
const hasGoogleApiKey = !!process.env['GOOGLE_API_KEY'];
|
2025-06-22 17:30:58 -07:00
|
|
|
if (!hasVertexProjectLocationConfig && !hasGoogleApiKey) {
|
|
|
|
|
return (
|
2025-07-08 09:37:10 -07:00
|
|
|
'When using Vertex AI, you must specify either:\n' +
|
2025-06-22 17:30:58 -07:00
|
|
|
'• GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION environment variables.\n' +
|
|
|
|
|
'• GOOGLE_API_KEY environment variable (if using express mode).\n' +
|
2025-07-08 09:37:10 -07:00
|
|
|
'Update your environment and try again (no reload needed if using .env)!'
|
2025-06-22 17:30:58 -07:00
|
|
|
);
|
2025-06-19 16:52:22 -07:00
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 'Invalid auth method selected.';
|
2025-08-28 13:52:25 -04:00
|
|
|
}
|