mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 04:04:06 -08:00
⚡ Fix credential overwrite via environment variables
This commit is contained in:
parent
6ffbd83fe1
commit
2f7ad6968e
|
@ -183,10 +183,6 @@ export class Start extends Command {
|
||||||
const loadNodesAndCredentials = LoadNodesAndCredentials();
|
const loadNodesAndCredentials = LoadNodesAndCredentials();
|
||||||
await loadNodesAndCredentials.init();
|
await loadNodesAndCredentials.init();
|
||||||
|
|
||||||
// Load the credentials overwrites if any exist
|
|
||||||
const credentialsOverwrites = CredentialsOverwrites();
|
|
||||||
await credentialsOverwrites.init();
|
|
||||||
|
|
||||||
// Load all external hooks
|
// Load all external hooks
|
||||||
const externalHooks = ExternalHooks();
|
const externalHooks = ExternalHooks();
|
||||||
await externalHooks.init();
|
await externalHooks.init();
|
||||||
|
@ -197,6 +193,10 @@ export class Start extends Command {
|
||||||
const credentialTypes = CredentialTypes();
|
const credentialTypes = CredentialTypes();
|
||||||
await credentialTypes.init(loadNodesAndCredentials.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
|
// Wait till the database is ready
|
||||||
await startDbInitPromise;
|
await startDbInitPromise;
|
||||||
|
|
||||||
|
|
|
@ -1,31 +1,13 @@
|
||||||
import { ICredentialType, ICredentialTypes as ICredentialTypesInterface } from 'n8n-workflow';
|
import { ICredentialType, ICredentialTypes as ICredentialTypesInterface } from 'n8n-workflow';
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-cycle
|
// eslint-disable-next-line import/no-cycle
|
||||||
import { CredentialsOverwrites, ICredentialsTypeData } from '.';
|
import { ICredentialsTypeData } from '.';
|
||||||
|
|
||||||
class CredentialTypesClass implements ICredentialTypesInterface {
|
class CredentialTypesClass implements ICredentialTypesInterface {
|
||||||
credentialTypes: ICredentialsTypeData = {};
|
credentialTypes: ICredentialsTypeData = {};
|
||||||
|
|
||||||
async init(credentialTypes: ICredentialsTypeData): Promise<void> {
|
async init(credentialTypes: ICredentialsTypeData): Promise<void> {
|
||||||
this.credentialTypes = credentialTypes;
|
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[] {
|
getAll(): ICredentialType[] {
|
||||||
|
|
|
@ -12,6 +12,9 @@ class CredentialsOverwritesClass {
|
||||||
private resolvedTypes: string[] = [];
|
private resolvedTypes: string[] = [];
|
||||||
|
|
||||||
async init(overwriteData?: ICredentialsOverwrite) {
|
async init(overwriteData?: ICredentialsOverwrite) {
|
||||||
|
// If data gets reinitialized reset the resolved types cache
|
||||||
|
this.resolvedTypes.length = 0;
|
||||||
|
|
||||||
if (overwriteData !== undefined) {
|
if (overwriteData !== undefined) {
|
||||||
// If data is already given it can directly be set instead of
|
// If data is already given it can directly be set instead of
|
||||||
// loaded from environment
|
// loaded from environment
|
||||||
|
@ -41,6 +44,7 @@ class CredentialsOverwritesClass {
|
||||||
|
|
||||||
if (overwrites && Object.keys(overwrites).length) {
|
if (overwrites && Object.keys(overwrites).length) {
|
||||||
this.overwriteData[type] = overwrites;
|
this.overwriteData[type] = overwrites;
|
||||||
|
credentialTypeData.__overwrittenProperties = Object.keys(overwrites);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,16 +27,7 @@
|
||||||
import * as express from 'express';
|
import * as express from 'express';
|
||||||
import { readFileSync } from 'fs';
|
import { readFileSync } from 'fs';
|
||||||
import { dirname as pathDirname, join as pathJoin, resolve as pathResolve } from 'path';
|
import { dirname as pathDirname, join as pathJoin, resolve as pathResolve } from 'path';
|
||||||
import {
|
import { FindManyOptions, getConnectionManager, In, IsNull, LessThanOrEqual, Not } from 'typeorm';
|
||||||
FindManyOptions,
|
|
||||||
FindOneOptions,
|
|
||||||
getConnectionManager,
|
|
||||||
In,
|
|
||||||
IsNull,
|
|
||||||
LessThanOrEqual,
|
|
||||||
Like,
|
|
||||||
Not,
|
|
||||||
} from 'typeorm';
|
|
||||||
import * as bodyParser from 'body-parser';
|
import * as bodyParser from 'body-parser';
|
||||||
import * as history from 'connect-history-api-fallback';
|
import * as history from 'connect-history-api-fallback';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
|
@ -47,7 +38,7 @@ import * as clientOAuth1 from 'oauth-1.0a';
|
||||||
import { RequestOptions } from 'oauth-1.0a';
|
import { RequestOptions } from 'oauth-1.0a';
|
||||||
import * as csrf from 'csrf';
|
import * as csrf from 'csrf';
|
||||||
import * as requestPromise from 'request-promise-native';
|
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
|
// IMPORTANT! Do not switch to anther bcrypt library unless really necessary and
|
||||||
// tested with all possible systems like Windows, Alpine on ARM, FreeBSD, ...
|
// tested with all possible systems like Windows, Alpine on ARM, FreeBSD, ...
|
||||||
import { compare } from 'bcryptjs';
|
import { compare } from 'bcryptjs';
|
||||||
|
@ -73,9 +64,7 @@ import {
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
INodeTypeNameVersion,
|
INodeTypeNameVersion,
|
||||||
IRunData,
|
|
||||||
INodeVersionedType,
|
INodeVersionedType,
|
||||||
ITelemetryClientConfig,
|
|
||||||
ITelemetrySettings,
|
ITelemetrySettings,
|
||||||
IWorkflowBase,
|
IWorkflowBase,
|
||||||
IWorkflowCredentials,
|
IWorkflowCredentials,
|
||||||
|
@ -134,7 +123,6 @@ import {
|
||||||
IWorkflowExecutionDataProcess,
|
IWorkflowExecutionDataProcess,
|
||||||
IWorkflowResponse,
|
IWorkflowResponse,
|
||||||
IPersonalizationSurveyAnswers,
|
IPersonalizationSurveyAnswers,
|
||||||
LoadNodesAndCredentials,
|
|
||||||
NodeTypes,
|
NodeTypes,
|
||||||
Push,
|
Push,
|
||||||
ResponseHelper,
|
ResponseHelper,
|
||||||
|
@ -2795,16 +2783,10 @@ class App {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadNodesAndCredentials = LoadNodesAndCredentials();
|
|
||||||
|
|
||||||
const credentialsOverwrites = CredentialsOverwrites();
|
const credentialsOverwrites = CredentialsOverwrites();
|
||||||
|
|
||||||
await credentialsOverwrites.init(body);
|
await credentialsOverwrites.init(body);
|
||||||
|
|
||||||
const credentialTypes = CredentialTypes();
|
|
||||||
|
|
||||||
await credentialTypes.init(loadNodesAndCredentials.credentialTypes);
|
|
||||||
|
|
||||||
this.presetCredentialsLoaded = true;
|
this.presetCredentialsLoaded = true;
|
||||||
|
|
||||||
ResponseHelper.sendSuccessResponse(res, { success: true }, true, 200);
|
ResponseHelper.sendSuccessResponse(res, { success: true }, true, 200);
|
||||||
|
|
Loading…
Reference in a new issue