From 9e0d2ccb3ac084d45e9ddb41a8f6854ee6cd138a Mon Sep 17 00:00:00 2001 From: Yongtae Date: Tue, 8 Aug 2023 10:39:13 +0900 Subject: [PATCH] Refactor GoogleAuth.credential to support both file path and JSON object credentials. Update GoogleVertexAIEmbedding to handle both cases --- .../credentials/GoogleAuth.credential.ts | 26 +++++++++++++++++-- .../GoogleVertexAIEmbedding.ts | 14 +++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/packages/components/credentials/GoogleAuth.credential.ts b/packages/components/credentials/GoogleAuth.credential.ts index d06d32b1..16b8e3b3 100644 --- a/packages/components/credentials/GoogleAuth.credential.ts +++ b/packages/components/credentials/GoogleAuth.credential.ts @@ -14,9 +14,31 @@ class GoogleVertexAuth implements INodeCredential { { label: 'Google Application Credential File Path', name: 'googleApplicationCredentialFilePath', - description: 'Path to your google application credential json file', + description: + 'Path to your google application credential json file. You can also use the credential JSON object (either one)', placeholder: 'your-path/application_default_credentials.json', - type: 'string' + type: 'string', + optional: true + }, + { + label: 'Google Credential JSON Object', + name: 'googleApplicationCredential', + description: 'JSON object of your google application credential. You can also use the file path (either one)', + placeholder: `{ + "type": ..., + "project_id": ..., + "private_key_id": ..., + "private_key": ..., + "client_email": ..., + "client_id": ..., + "auth_uri": ..., + "token_uri": ..., + "auth_provider_x509_cert_url": ..., + "client_x509_cert_url": ... +}`, + type: 'string', + rows: 4, + optional: true }, { label: 'Project ID', diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index d68911a9..23bd3565 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -36,12 +36,18 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { const credentialData = await getCredentialData(nodeData.credential ?? '', options) const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) - if (!googleApplicationCredentialFilePath) throw new Error('Please specify your Google Application Credential file path') + const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData) const projectID = getCredentialParam('projectID', credentialData, nodeData) - const authOptions: GoogleAuthOptions = { - keyFile: googleApplicationCredentialFilePath - } + if (!googleApplicationCredentialFilePath && !googleApplicationCredential) + throw new Error('Please specify your Google Application Credential') + if (googleApplicationCredentialFilePath && googleApplicationCredential) + throw new Error('Please use either Google Application Credential File Path or Google Credential JSON Object') + + const authOptions: GoogleAuthOptions = {} + if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath + else if (!googleApplicationCredentialFilePath && googleApplicationCredential) + authOptions.credentials = JSON.parse(googleApplicationCredential) if (projectID) authOptions.projectId = projectID