(credentialId: string, workspaceId: string)
| 125 | } |
| 126 | |
| 127 | const getCredentialById = async (credentialId: string, workspaceId: string): Promise<any> => { |
| 128 | try { |
| 129 | const appServer = getRunningExpressApp() |
| 130 | const credential = await appServer.AppDataSource.getRepository(Credential).findOneBy({ |
| 131 | id: credentialId, |
| 132 | workspaceId: workspaceId |
| 133 | }) |
| 134 | if (!credential) { |
| 135 | throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Credential ${credentialId} not found`) |
| 136 | } |
| 137 | // Decrpyt credentialData |
| 138 | const decryptedCredentialData = await decryptCredentialData( |
| 139 | credential.encryptedData, |
| 140 | credential.credentialName, |
| 141 | appServer.nodesPool.componentCredentials |
| 142 | ) |
| 143 | const returnCredential: ICredentialReturnResponse = { |
| 144 | ...credential, |
| 145 | plainDataObj: decryptedCredentialData |
| 146 | } |
| 147 | const dbResponse: any = omit(returnCredential, ['encryptedData']) |
| 148 | if (workspaceId) { |
| 149 | const shared = await appServer.AppDataSource.getRepository(WorkspaceShared).count({ |
| 150 | where: { |
| 151 | workspaceId: workspaceId, |
| 152 | sharedItemId: credentialId, |
| 153 | itemType: 'credential' |
| 154 | } |
| 155 | }) |
| 156 | if (shared > 0) { |
| 157 | dbResponse.shared = true |
| 158 | } |
| 159 | } |
| 160 | return dbResponse |
| 161 | } catch (error) { |
| 162 | throw new InternalFlowiseError( |
| 163 | StatusCodes.INTERNAL_SERVER_ERROR, |
| 164 | `Error: credentialsService.createCredential - ${getErrorMessage(error)}` |
| 165 | ) |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | const updateCredential = async (credentialId: string, requestBody: any, workspaceId: string): Promise<any> => { |
| 170 | try { |
nothing calls this directly
no test coverage detected