Skip to content

Commit

Permalink
remove nodeToTestWith
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Nov 29, 2022
1 parent 9950748 commit a25cd6f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 25 deletions.
29 changes: 11 additions & 18 deletions packages/cli/src/CredentialsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,10 @@ export class CredentialsHelper extends ICredentialsHelper {
await Db.collections.Credentials.update(findQuery, newCredentialsData);
}

getCredentialTestFunction(
private getCredentialTestFunction(
credentialType: string,
nodeToTestWith?: string,
): ICredentialTestFunction | ICredentialTestRequestData | undefined {
const nodeTypesToTestWith = nodeToTestWith
? [nodeToTestWith]
: this.credentialTypes.getNodeTypesToTestWith(credentialType);

const nodeTypesToTestWith = this.credentialTypes.getNodeTypesToTestWith(credentialType);
for (const nodeName of nodeTypesToTestWith) {
const node = this.nodeTypes.getByName(nodeName);

Expand All @@ -490,31 +486,29 @@ export class CredentialsHelper extends ICredentialsHelper {
// Check each of the node versions for credential tests
for (const nodeType of allNodeTypes) {
// Check each of teh credentials
for (const credential of nodeType.description.credentials ?? []) {
if (credential.name === credentialType && !!credential.testedBy) {
if (typeof credential.testedBy === 'string') {
for (const { name, testedBy } of nodeType.description.credentials ?? []) {
if (name === credentialType && !!testedBy) {
if (typeof testedBy === 'string') {
if (node instanceof VersionedNodeType) {
// The node is versioned. So check all versions for test function
// starting with the latest
const versions = Object.keys(node.nodeVersions).sort().reverse();
for (const version of versions) {
const versionedNode = node.nodeVersions[parseInt(version, 10)];
if (
versionedNode.methods?.credentialTest &&
versionedNode.methods?.credentialTest[credential.testedBy]
) {
return versionedNode.methods?.credentialTest[credential.testedBy];
const credentialTest = versionedNode.methods?.credentialTest;
if (credentialTest && testedBy in credentialTest) {
return credentialTest[testedBy];
}
}
}
// Test is defined as string which links to a function
return (node as unknown as INodeType).methods?.credentialTest![credential.testedBy];
return (node as unknown as INodeType).methods?.credentialTest![testedBy];
}

// Test is defined as JSON with a definition for the request to make
return {
nodeType,
testRequest: credential.testedBy,
testRequest: testedBy,
};
}
}
Expand All @@ -536,9 +530,8 @@ export class CredentialsHelper extends ICredentialsHelper {
user: User,
credentialType: string,
credentialsDecrypted: ICredentialsDecrypted,
nodeToTestWith?: string,
): Promise<INodeCredentialTestResult> {
const credentialTestFunction = this.getCredentialTestFunction(credentialType, nodeToTestWith);
const credentialTestFunction = this.getCredentialTestFunction(credentialType);
if (credentialTestFunction === undefined) {
return Promise.resolve({
status: 'Error',
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/credentials/credentials.controller.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ EECredentialsController.get(
EECredentialsController.post(
'/test',
ResponseHelper.send(async (req: CredentialRequest.Test): Promise<INodeCredentialTestResult> => {
const { credentials, nodeToTestWith } = req.body;
const { credentials } = req.body;

const encryptionKey = await EECredentials.getEncryptionKey();

Expand All @@ -122,7 +122,7 @@ EECredentialsController.post(
Object.assign(credentials, { data: decryptedData });
}

return EECredentials.test(req.user, encryptionKey, credentials, nodeToTestWith);
return EECredentials.test(req.user, encryptionKey, credentials);
}),
);

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/credentials/credentials.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ credentialsController.get(
credentialsController.post(
'/test',
ResponseHelper.send(async (req: CredentialRequest.Test): Promise<INodeCredentialTestResult> => {
const { credentials, nodeToTestWith } = req.body;
const { credentials } = req.body;

const encryptionKey = await CredentialsService.getEncryptionKey();
return CredentialsService.test(req.user, encryptionKey, credentials, nodeToTestWith);
return CredentialsService.test(req.user, encryptionKey, credentials);
}),
);

Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/credentials/credentials.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,9 @@ export class CredentialsService {
user: User,
encryptionKey: string,
credentials: ICredentialsDecrypted,
nodeToTestWith: string | undefined,
): Promise<INodeCredentialTestResult> {
const helper = new CredentialsHelper(encryptionKey);

return helper.testCredentials(user, credentials.type, credentials, nodeToTestWith);
return helper.testCredentials(user, credentials.type, credentials);
}
}
1 change: 0 additions & 1 deletion packages/workflow/src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,6 @@ export interface INodeCredentialTestResult {
}

export interface INodeCredentialTestRequest {
nodeToTestWith?: string; // node name i.e. slack
credentials: ICredentialsDecrypted;
}

Expand Down

0 comments on commit a25cd6f

Please sign in to comment.