mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Sync upstream Gemini-CLI v0.8.2 (#838)
This commit is contained in:
@@ -4,9 +4,12 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { AuthType, type Config } from '@qwen-code/qwen-code-core';
|
||||
import type { Config } from '@qwen-code/qwen-code-core';
|
||||
import { AuthType, OutputFormat } from '@qwen-code/qwen-code-core';
|
||||
import { USER_SETTINGS_PATH } from './config/settings.js';
|
||||
import { validateAuthMethod } from './config/auth.js';
|
||||
import { type LoadedSettings } from './config/settings.js';
|
||||
import { handleError } from './utils/errors.js';
|
||||
|
||||
function getAuthTypeFromEnv(): AuthType | undefined {
|
||||
if (process.env['GOOGLE_GENAI_USE_GCA'] === 'true') {
|
||||
@@ -28,24 +31,47 @@ export async function validateNonInteractiveAuth(
|
||||
configuredAuthType: AuthType | undefined,
|
||||
useExternalAuth: boolean | undefined,
|
||||
nonInteractiveConfig: Config,
|
||||
settings: LoadedSettings,
|
||||
) {
|
||||
const effectiveAuthType = configuredAuthType || getAuthTypeFromEnv();
|
||||
try {
|
||||
const enforcedType = settings.merged.security?.auth?.enforcedType;
|
||||
if (enforcedType) {
|
||||
const currentAuthType = getAuthTypeFromEnv();
|
||||
if (currentAuthType !== enforcedType) {
|
||||
const message = `The configured auth type is ${enforcedType}, but the current auth type is ${currentAuthType}. Please re-authenticate with the correct type.`;
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
|
||||
if (!effectiveAuthType) {
|
||||
console.error(
|
||||
`Please set an Auth method in your ${USER_SETTINGS_PATH} or specify one of the following environment variables before running: GEMINI_API_KEY, OPENAI_API_KEY, GOOGLE_GENAI_USE_VERTEXAI, GOOGLE_GENAI_USE_GCA`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
const effectiveAuthType =
|
||||
enforcedType || getAuthTypeFromEnv() || configuredAuthType;
|
||||
|
||||
if (!useExternalAuth) {
|
||||
const err = validateAuthMethod(effectiveAuthType);
|
||||
if (err != null) {
|
||||
console.error(err);
|
||||
if (!effectiveAuthType) {
|
||||
const message = `Please set an Auth method in your ${USER_SETTINGS_PATH} or specify one of the following environment variables before running: GEMINI_API_KEY, OPENAI_API_KEY, GOOGLE_GENAI_USE_VERTEXAI, GOOGLE_GENAI_USE_GCA`;
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
const authType: AuthType = effectiveAuthType as AuthType;
|
||||
|
||||
if (!useExternalAuth) {
|
||||
const err = validateAuthMethod(String(authType));
|
||||
if (err != null) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
|
||||
await nonInteractiveConfig.refreshAuth(authType);
|
||||
return nonInteractiveConfig;
|
||||
} catch (error) {
|
||||
if (nonInteractiveConfig.getOutputFormat() === OutputFormat.JSON) {
|
||||
handleError(
|
||||
error instanceof Error ? error : new Error(String(error)),
|
||||
nonInteractiveConfig,
|
||||
1,
|
||||
);
|
||||
} else {
|
||||
console.error(error instanceof Error ? error.message : String(error));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
await nonInteractiveConfig.refreshAuth(effectiveAuthType);
|
||||
return nonInteractiveConfig;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user