diff --git a/packages/cli/src/CredentialsOverwrites.ts b/packages/cli/src/CredentialsOverwrites.ts index 40b6419dab..bd962ae50e 100644 --- a/packages/cli/src/CredentialsOverwrites.ts +++ b/packages/cli/src/CredentialsOverwrites.ts @@ -3,6 +3,7 @@ import { } from 'n8n-workflow'; import { + CredentialTypes, ICredentialsOverwrite, GenericHelpers, } from './'; @@ -49,7 +50,27 @@ class CredentialsOverwritesClass { } get(type: string): ICredentialDataDecryptedObject | undefined { - return this.overwriteData[type]; + const credentialTypes = CredentialTypes(); + const credentialTypeData = credentialTypes.getByName(type); + + if (credentialTypeData === undefined) { + throw new Error(`The credentials of type "${type}" are not known.`); + } + + if (credentialTypeData.extends === undefined) { + return this.overwriteData[type]; + } + + const overwrites: ICredentialDataDecryptedObject = {}; + for (const credentialsTypeName of credentialTypeData.extends) { + Object.assign(overwrites, this.get(credentialsTypeName)); + } + + if (this.overwriteData[type] !== undefined) { + Object.assign(overwrites, this.overwriteData[type]); + } + + return overwrites; } getAll(): ICredentialsOverwrite { diff --git a/packages/cli/src/WorkflowRunner.ts b/packages/cli/src/WorkflowRunner.ts index 0eb4f7a016..f0171322a5 100644 --- a/packages/cli/src/WorkflowRunner.ts +++ b/packages/cli/src/WorkflowRunner.ts @@ -212,6 +212,7 @@ export class WorkflowRunner { let nodeTypeData: ITransferNodeTypes; let credentialTypeData: ICredentialsTypeData; + let credentialsOverwrites = this.credentialsOverwrites; if (loadAllNodeTypes === true) { // Supply all nodeTypes and credentialTypes @@ -219,15 +220,22 @@ export class WorkflowRunner { const credentialTypes = CredentialTypes(); credentialTypeData = credentialTypes.credentialTypes; } else { - // Supply only nodeTypes and credentialTypes which the workflow needs + // Supply only nodeTypes, credentialTypes and overwrites that the workflow needs nodeTypeData = WorkflowHelpers.getNodeTypeData(data.workflowData.nodes); credentialTypeData = WorkflowHelpers.getCredentialsData(data.credentials); + + credentialsOverwrites = {}; + for (const credentialName of Object.keys(credentialTypeData)) { + if (this.credentialsOverwrites[credentialName] !== undefined) { + credentialsOverwrites[credentialName] = this.credentialsOverwrites[credentialName]; + } + } } (data as unknown as IWorkflowExecutionDataProcessWithExecution).executionId = executionId; (data as unknown as IWorkflowExecutionDataProcessWithExecution).nodeTypeData = nodeTypeData; - (data as unknown as IWorkflowExecutionDataProcessWithExecution).credentialsOverwrite = this.credentialsOverwrites; + (data as unknown as IWorkflowExecutionDataProcessWithExecution).credentialsOverwrite = credentialsOverwrites; (data as unknown as IWorkflowExecutionDataProcessWithExecution).credentialsTypeData = credentialTypeData; // TODO: Still needs correct value const workflowHooks = WorkflowExecuteAdditionalData.getWorkflowHooksMain(data, executionId); diff --git a/packages/cli/src/WorkflowRunnerProcess.ts b/packages/cli/src/WorkflowRunnerProcess.ts index 41f467a8fd..c46d5f3dd4 100644 --- a/packages/cli/src/WorkflowRunnerProcess.ts +++ b/packages/cli/src/WorkflowRunnerProcess.ts @@ -66,7 +66,7 @@ export class WorkflowRunnerProcess { // Load the credentials overwrites if any exist const credentialsOverwrites = CredentialsOverwrites(); - await credentialsOverwrites.init(); + await credentialsOverwrites.init(inputData.credentialsOverwrite); this.workflow = new Workflow({ id: this.data.workflowData.id as string | undefined, name: this.data.workflowData.name, nodes: this.data.workflowData!.nodes, connections: this.data.workflowData!.connections, active: this.data.workflowData!.active, nodeTypes, staticData: this.data.workflowData!.staticData, settings: this.data.workflowData!.settings}); const additionalData = await WorkflowExecuteAdditionalData.getBase(this.data.credentials);