mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
feat(auth): Enhance non-interactive gcp auth (#4811)
This commit is contained in:
@@ -8,21 +8,28 @@ import { AuthType, Config } from '@google/gemini-cli-core';
|
||||
import { USER_SETTINGS_PATH } from './config/settings.js';
|
||||
import { validateAuthMethod } from './config/auth.js';
|
||||
|
||||
function getAuthTypeFromEnv(): AuthType | undefined {
|
||||
if (process.env.GOOGLE_GENAI_USE_GCA === 'true') {
|
||||
return AuthType.LOGIN_WITH_GOOGLE;
|
||||
}
|
||||
if (process.env.GOOGLE_GENAI_USE_VERTEXAI === 'true') {
|
||||
return AuthType.USE_VERTEX_AI;
|
||||
}
|
||||
if (process.env.GEMINI_API_KEY) {
|
||||
return AuthType.USE_GEMINI;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
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);
|
||||
const effectiveAuthType = configuredAuthType || getAuthTypeFromEnv();
|
||||
|
||||
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`,
|
||||
`Please set an Auth method in your ${USER_SETTINGS_PATH} or specify one of the following environment variables before running: GEMINI_API_KEY, GOOGLE_GENAI_USE_VERTEXAI, GOOGLE_GENAI_USE_GCA`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user