fix(Google Vertex Chat Model Node): Clean service account private key (#10770)

This commit is contained in:
Eugene 2024-09-17 09:18:45 +02:00 committed by GitHub
parent d14bb36300
commit e6d84db899
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,6 +12,7 @@ import {
import { ChatVertexAI } from '@langchain/google-vertexai'; import { ChatVertexAI } from '@langchain/google-vertexai';
import type { SafetySetting } from '@google/generative-ai'; import type { SafetySetting } from '@google/generative-ai';
import { ProjectsClient } from '@google-cloud/resource-manager'; import { ProjectsClient } from '@google-cloud/resource-manager';
import { formatPrivateKey } from 'n8n-nodes-base/dist/utils/utilities';
import { getConnectionHintNoticeField } from '../../../utils/sharedFields'; import { getConnectionHintNoticeField } from '../../../utils/sharedFields';
import { N8nLlmTracing } from '../N8nLlmTracing'; import { N8nLlmTracing } from '../N8nLlmTracing';
import { additionalOptions } from '../gemini-common/additional-options'; import { additionalOptions } from '../gemini-common/additional-options';
@ -97,11 +98,13 @@ export class LmChatGoogleVertex implements INodeType {
const results: Array<{ name: string; value: string }> = []; const results: Array<{ name: string; value: string }> = [];
const credentials = await this.getCredentials('googleApi'); const credentials = await this.getCredentials('googleApi');
const privateKey = formatPrivateKey(credentials.privateKey as string);
const email = (credentials.email as string).trim();
const client = new ProjectsClient({ const client = new ProjectsClient({
credentials: { credentials: {
client_email: credentials.email as string, client_email: email,
private_key: credentials.privateKey as string, private_key: privateKey,
}, },
}); });
@ -123,6 +126,8 @@ export class LmChatGoogleVertex implements INodeType {
async supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData> { async supplyData(this: IExecuteFunctions, itemIndex: number): Promise<SupplyData> {
const credentials = await this.getCredentials('googleApi'); const credentials = await this.getCredentials('googleApi');
const privateKey = formatPrivateKey(credentials.privateKey as string);
const email = (credentials.email as string).trim();
const modelName = this.getNodeParameter('modelName', itemIndex) as string; const modelName = this.getNodeParameter('modelName', itemIndex) as string;
@ -153,8 +158,8 @@ export class LmChatGoogleVertex implements INodeType {
authOptions: { authOptions: {
projectId, projectId,
credentials: { credentials: {
client_email: credentials.email as string, client_email: email,
private_key: credentials.privateKey as string, private_key: privateKey,
}, },
}, },
model: modelName, model: modelName,