Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions packages/core/src/core/contentGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,6 @@ export async function createContentGeneratorConfig(
customHeaders?: Record<string, string>,
vertexAiRouting?: VertexAiRoutingConfig,
): Promise<ContentGeneratorConfig> {
const geminiApiKey =
apiKey ||
process.env['GEMINI_API_KEY'] ||
(await loadApiKey()) ||
undefined;
const googleApiKey = process.env['GOOGLE_API_KEY'] || undefined;
const googleCloudProject =
process.env['GOOGLE_CLOUD_PROJECT'] ||
process.env['GOOGLE_CLOUD_PROJECT_ID'] ||
undefined;
const googleCloudLocation = process.env['GOOGLE_CLOUD_LOCATION'] || undefined;

const contentGeneratorConfig: ContentGeneratorConfig = {
authType,
proxy: config?.getProxy(),
Expand All @@ -150,14 +138,28 @@ export async function createContentGeneratorConfig(
vertexAiRouting,
};

// If we are using Google auth or we are in Cloud Shell, there is nothing else to validate for now
// If we are using Google auth or we are in Cloud Shell, there is nothing else to validate for now.
// Return before touching the API-key keychain: on Linux without a Secret Service
// (WSL/SSH/Docker/CI) keytar can block indefinitely on its functional probe.
if (
authType === AuthType.LOGIN_WITH_GOOGLE ||
authType === AuthType.COMPUTE_ADC
) {
return contentGeneratorConfig;
}

const geminiApiKey =
apiKey ||
process.env['GEMINI_API_KEY'] ||
(await loadApiKey()) ||
undefined;
const googleApiKey = process.env['GOOGLE_API_KEY'] || undefined;
const googleCloudProject =
process.env['GOOGLE_CLOUD_PROJECT'] ||
process.env['GOOGLE_CLOUD_PROJECT_ID'] ||
undefined;
const googleCloudLocation = process.env['GOOGLE_CLOUD_LOCATION'] || undefined;

if (authType === AuthType.USE_GEMINI && geminiApiKey) {
contentGeneratorConfig.apiKey = geminiApiKey;
contentGeneratorConfig.vertexai = false;
Expand Down
13 changes: 11 additions & 2 deletions packages/core/src/services/keychainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,20 @@ export class KeychainService {
return null;
}

if (await this.isKeychainFunctional(keychainModule)) {
// Cap the functional probe so a non-responsive Secret Service (common on
Comment thread
scidomino marked this conversation as resolved.
Outdated
// headless Linux: WSL/SSH/Docker without gnome-keyring or D-Bus) falls back
// to FileKeychain instead of hanging the CLI indefinitely.
const functional = await Promise.race([
this.isKeychainFunctional(keychainModule),
new Promise<false>((resolve) =>
setTimeout(() => resolve(false), 2000).unref(),
),
]);
if (functional) {
return keychainModule;
}

debugLogger.debug('Keychain functional verification failed');
debugLogger.debug('Keychain functional verification failed or timed out');
return null;
} catch (error) {
// Avoid logging full error objects to prevent PII exposure.
Expand Down