mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-08-04 06:52:47 +00:00
🧯 fix: Suppress Google Service Key Noise (#13322)
* fix: suppress unused Google service key noise * test: stabilize Google endpoint config mocks * fix: normalize Google service key endpoint config
This commit is contained in:
parent
a00800161c
commit
cb23d6b993
4 changed files with 229 additions and 10 deletions
|
|
@ -1,10 +1,34 @@
|
|||
const path = require('path');
|
||||
const fs = require('fs/promises');
|
||||
const { logger } = require('@librechat/data-schemas');
|
||||
const { loadServiceKey, isUserProvided } = require('@librechat/api');
|
||||
const { config } = require('./EndpointService');
|
||||
|
||||
const defaultServiceKeyPath = path.join(__dirname, '../../..', 'data', 'auth.json');
|
||||
|
||||
async function getServiceKeyPath() {
|
||||
const serviceKeyPath = process.env.GOOGLE_SERVICE_KEY_FILE?.trim();
|
||||
if (serviceKeyPath) {
|
||||
return serviceKeyPath;
|
||||
}
|
||||
|
||||
try {
|
||||
await fs.access(defaultServiceKeyPath);
|
||||
return defaultServiceKeyPath;
|
||||
} catch (error) {
|
||||
if (error?.code !== 'ENOENT') {
|
||||
logger.warn(
|
||||
`Unable to access default Google service key file: ${defaultServiceKeyPath}`,
|
||||
error,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadAsyncEndpoints() {
|
||||
let serviceKey, googleUserProvides;
|
||||
let serviceKey;
|
||||
let googleUserProvides = false;
|
||||
const { googleKey } = config;
|
||||
|
||||
/** Check if GOOGLE_KEY is provided at all(including 'user_provided') */
|
||||
|
|
@ -14,15 +38,15 @@ async function loadAsyncEndpoints() {
|
|||
/** If GOOGLE_KEY is provided, check if it's user_provided */
|
||||
googleUserProvides = isUserProvided(googleKey);
|
||||
} else {
|
||||
/** Only attempt to load service key if GOOGLE_KEY is not provided */
|
||||
const serviceKeyPath =
|
||||
process.env.GOOGLE_SERVICE_KEY_FILE || path.join(__dirname, '../../..', 'data', 'auth.json');
|
||||
const serviceKeyPath = await getServiceKeyPath();
|
||||
|
||||
try {
|
||||
serviceKey = await loadServiceKey(serviceKeyPath);
|
||||
} catch (error) {
|
||||
logger.error('Error loading service key', error);
|
||||
serviceKey = null;
|
||||
if (serviceKeyPath) {
|
||||
try {
|
||||
serviceKey = await loadServiceKey(serviceKeyPath);
|
||||
} catch (error) {
|
||||
logger.warn('Error loading Google service key', error);
|
||||
serviceKey = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue