mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-26 21:00:23 +03:00
Refactor GoogleAuth.credential to support both file path and JSON object credentials. Update GoogleVertexAIEmbedding to handle both cases
This commit is contained in:
@@ -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',
|
||||
|
||||
+10
-4
@@ -36,12 +36,18 @@ class GoogleVertexAIEmbedding_Embeddings implements INode {
|
||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user