diff --git a/packages/cli/commands/start.ts b/packages/cli/commands/start.ts index 39e2786c02..3ecbddc0e7 100644 --- a/packages/cli/commands/start.ts +++ b/packages/cli/commands/start.ts @@ -183,10 +183,6 @@ export class Start extends Command { const loadNodesAndCredentials = LoadNodesAndCredentials(); await loadNodesAndCredentials.init(); - // Load the credentials overwrites if any exist - const credentialsOverwrites = CredentialsOverwrites(); - await credentialsOverwrites.init(); - // Load all external hooks const externalHooks = ExternalHooks(); await externalHooks.init(); @@ -197,6 +193,10 @@ export class Start extends Command { const credentialTypes = CredentialTypes(); await credentialTypes.init(loadNodesAndCredentials.credentialTypes); + // Load the credentials overwrites if any exist + const credentialsOverwrites = CredentialsOverwrites(); + await credentialsOverwrites.init(); + // Wait till the database is ready await startDbInitPromise; diff --git a/packages/cli/src/CredentialTypes.ts b/packages/cli/src/CredentialTypes.ts index f9c3504377..0d35381054 100644 --- a/packages/cli/src/CredentialTypes.ts +++ b/packages/cli/src/CredentialTypes.ts @@ -1,31 +1,13 @@ import { ICredentialType, ICredentialTypes as ICredentialTypesInterface } from 'n8n-workflow'; // eslint-disable-next-line import/no-cycle -import { CredentialsOverwrites, ICredentialsTypeData } from '.'; +import { ICredentialsTypeData } from '.'; class CredentialTypesClass implements ICredentialTypesInterface { credentialTypes: ICredentialsTypeData = {}; async init(credentialTypes: ICredentialsTypeData): Promise { this.credentialTypes = credentialTypes; - - // Load the credentials overwrites if any exist - const credentialsOverwrites = CredentialsOverwrites().getAll(); - - // eslint-disable-next-line no-restricted-syntax - for (const credentialType of Object.keys(credentialsOverwrites)) { - if (credentialTypes[credentialType] === undefined) { - // eslint-disable-next-line no-continue - continue; - } - - // Add which properties got overwritten that the Editor-UI knows - // which properties it should hide - // eslint-disable-next-line no-underscore-dangle, no-param-reassign - credentialTypes[credentialType].__overwrittenProperties = Object.keys( - credentialsOverwrites[credentialType], - ); - } } getAll(): ICredentialType[] { diff --git a/packages/cli/src/CredentialsOverwrites.ts b/packages/cli/src/CredentialsOverwrites.ts index 4fbdbf3e61..077d08eb14 100644 --- a/packages/cli/src/CredentialsOverwrites.ts +++ b/packages/cli/src/CredentialsOverwrites.ts @@ -12,6 +12,9 @@ class CredentialsOverwritesClass { private resolvedTypes: string[] = []; async init(overwriteData?: ICredentialsOverwrite) { + // If data gets reinitialized reset the resolved types cache + this.resolvedTypes.length = 0; + if (overwriteData !== undefined) { // If data is already given it can directly be set instead of // loaded from environment @@ -41,6 +44,7 @@ class CredentialsOverwritesClass { if (overwrites && Object.keys(overwrites).length) { this.overwriteData[type] = overwrites; + credentialTypeData.__overwrittenProperties = Object.keys(overwrites); } } } diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index aead6ad68f..3532ad9c4b 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -27,16 +27,7 @@ import * as express from 'express'; import { readFileSync } from 'fs'; import { dirname as pathDirname, join as pathJoin, resolve as pathResolve } from 'path'; -import { - FindManyOptions, - FindOneOptions, - getConnectionManager, - In, - IsNull, - LessThanOrEqual, - Like, - Not, -} from 'typeorm'; +import { FindManyOptions, getConnectionManager, In, IsNull, LessThanOrEqual, Not } from 'typeorm'; import * as bodyParser from 'body-parser'; import * as history from 'connect-history-api-fallback'; import * as os from 'os'; @@ -47,7 +38,7 @@ import * as clientOAuth1 from 'oauth-1.0a'; import { RequestOptions } from 'oauth-1.0a'; import * as csrf from 'csrf'; import * as requestPromise from 'request-promise-native'; -import { createHash, createHmac } from 'crypto'; +import { createHmac } from 'crypto'; // IMPORTANT! Do not switch to anther bcrypt library unless really necessary and // tested with all possible systems like Windows, Alpine on ARM, FreeBSD, ... import { compare } from 'bcryptjs'; @@ -73,9 +64,7 @@ import { INodeType, INodeTypeDescription, INodeTypeNameVersion, - IRunData, INodeVersionedType, - ITelemetryClientConfig, ITelemetrySettings, IWorkflowBase, IWorkflowCredentials, @@ -134,7 +123,6 @@ import { IWorkflowExecutionDataProcess, IWorkflowResponse, IPersonalizationSurveyAnswers, - LoadNodesAndCredentials, NodeTypes, Push, ResponseHelper, @@ -2795,16 +2783,10 @@ class App { return; } - const loadNodesAndCredentials = LoadNodesAndCredentials(); - const credentialsOverwrites = CredentialsOverwrites(); await credentialsOverwrites.init(body); - const credentialTypes = CredentialTypes(); - - await credentialTypes.init(loadNodesAndCredentials.credentialTypes); - this.presetCredentialsLoaded = true; ResponseHelper.sendSuccessResponse(res, { success: true }, true, 200);