(nodeData: INodeData, options: ICommonObject)
| 4 | type SupportedAuthOptions = ChatVertexAIInput['authOptions'] | VertexAIInput['authOptions'] |
| 5 | |
| 6 | export const buildGoogleCredentials = async (nodeData: INodeData, options: ICommonObject): Promise<SupportedAuthOptions | null> => { |
| 7 | const credentialData = await getCredentialData(nodeData.credential ?? '', options) |
| 8 | const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) |
| 9 | const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData) |
| 10 | const projectID = getCredentialParam('projectID', credentialData, nodeData) |
| 11 | |
| 12 | const authOptions: any = {} |
| 13 | if (Object.keys(credentialData).length !== 0) { |
| 14 | if (!googleApplicationCredentialFilePath && !googleApplicationCredential) |
| 15 | throw new Error('Please specify your Google Application Credential') |
| 16 | if (!googleApplicationCredentialFilePath && !googleApplicationCredential) |
| 17 | throw new Error( |
| 18 | 'Error: More than one component has been inputted. Please use only one of the following: Google Application Credential File Path or Google Credential JSON Object' |
| 19 | ) |
| 20 | |
| 21 | if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath |
| 22 | else if (!googleApplicationCredentialFilePath && googleApplicationCredential) |
| 23 | authOptions.credentials = JSON.parse(googleApplicationCredential) |
| 24 | |
| 25 | if (projectID) authOptions.projectId = projectID |
| 26 | } |
| 27 | |
| 28 | return authOptions |
| 29 | } |
no test coverage detected