refactor(core): Port nodes config (no-changelog) (#10140)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Iván Ovejero
2024-07-23 13:32:50 +02:00
committed by GitHub
parent d2a3a4a080
commit 95b85dd5c1
14 changed files with 95 additions and 65 deletions

View File

@@ -19,7 +19,6 @@ import type {
} from 'n8n-workflow';
import { ApplicationError, ErrorReporterProxy as ErrorReporter } from 'n8n-workflow';
import config from '@/config';
import {
CUSTOM_API_CALL_KEY,
CUSTOM_API_CALL_NAME,
@@ -28,6 +27,7 @@ import {
inE2ETests,
} from '@/constants';
import { Logger } from '@/Logger';
import { GlobalConfig } from '@n8n/config';
interface LoadedNodesAndCredentials {
nodes: INodeTypeData;
@@ -44,15 +44,16 @@ export class LoadNodesAndCredentials {
loaders: Record<string, DirectoryLoader> = {};
excludeNodes = config.getEnv('nodes.exclude');
excludeNodes = this.globalConfig.nodes.exclude;
includeNodes = config.getEnv('nodes.include');
includeNodes = this.globalConfig.nodes.include;
private postProcessors: Array<() => Promise<void>> = [];
constructor(
private readonly logger: Logger,
private readonly instanceSettings: InstanceSettings,
private readonly globalConfig: GlobalConfig,
) {}
async init() {

View File

@@ -120,7 +120,7 @@ export class Server extends AbstractServer {
await Container.get(LdapService).init();
}
if (config.getEnv('nodes.communityPackages.enabled')) {
if (this.globalConfig.nodes.communityPackages.enabled) {
await import('@/controllers/communityPackages.controller');
}

View File

@@ -72,8 +72,7 @@ import { UrlService } from './services/url.service';
import { WorkflowExecutionService } from './workflows/workflowExecution.service';
import { MessageEventBus } from '@/eventbus/MessageEventBus/MessageEventBus';
import { EventService } from './eventbus/event.service';
const ERROR_TRIGGER_TYPE = config.getEnv('nodes.errorTriggerType');
import { GlobalConfig } from '@n8n/config';
export function objectToError(errorObject: unknown, workflow: Workflow): Error {
// TODO: Expand with other error types
@@ -176,6 +175,7 @@ export function executeErrorWorkflow(
};
}
const { errorTriggerType } = Container.get(GlobalConfig).nodes;
// Run the error workflow
// To avoid an infinite loop do not run the error workflow again if the error-workflow itself failed and it is its own error-workflow.
const { errorWorkflow } = workflowData.settings ?? {};
@@ -220,7 +220,7 @@ export function executeErrorWorkflow(
} else if (
mode !== 'error' &&
workflowId !== undefined &&
workflowData.nodes.some((node) => node.type === ERROR_TRIGGER_TYPE)
workflowData.nodes.some((node) => node.type === errorTriggerType)
) {
logger.verbose('Start internal error workflow', { executionId, workflowId });
void Container.get(OwnershipService)

View File

@@ -252,16 +252,15 @@ export class Start extends BaseCommand {
config.set(setting.key, jsonParse(setting.value, { fallbackValue: setting.value }));
});
const areCommunityPackagesEnabled = config.getEnv('nodes.communityPackages.enabled');
const globalConfig = Container.get(GlobalConfig);
if (areCommunityPackagesEnabled) {
if (globalConfig.nodes.communityPackages.enabled) {
const { CommunityPackagesService } = await import('@/services/communityPackages.service');
await Container.get(CommunityPackagesService).setMissingPackages({
reinstallMissingPackages: flags.reinstallMissingPackages,
});
}
const globalConfig = Container.get(GlobalConfig);
const { type: dbType } = globalConfig.database;
if (dbType === 'sqlite') {
const shouldRunVacuum = globalConfig.database.sqlite.executeVacuumOnStartup;

View File

@@ -2,18 +2,9 @@ import path from 'path';
import convict from 'convict';
import { Container } from 'typedi';
import { InstanceSettings } from 'n8n-core';
import { LOG_LEVELS, jsonParse } from 'n8n-workflow';
import { LOG_LEVELS } from 'n8n-workflow';
import { ensureStringArray } from './utils';
convict.addFormat({
name: 'json-string-array',
coerce: (rawStr: string) =>
jsonParse<string[]>(rawStr, {
errorMessage: `Expected this value "${rawStr}" to be valid JSON`,
}),
validate: ensureStringArray,
});
convict.addFormat({
name: 'comma-separated-list',
coerce: (rawStr: string) => rawStr.split(','),
@@ -615,35 +606,6 @@ export const schema = {
env: 'EXTERNAL_HOOK_FILES',
},
nodes: {
include: {
doc: 'Nodes to load',
format: 'json-string-array',
default: undefined,
env: 'NODES_INCLUDE',
},
exclude: {
doc: 'Nodes not to load',
format: 'json-string-array',
default: undefined,
env: 'NODES_EXCLUDE',
},
errorTriggerType: {
doc: 'Node Type to use as Error Trigger',
format: String,
default: 'n8n-nodes-base.errorTrigger',
env: 'NODES_ERROR_TRIGGER_TYPE',
},
communityPackages: {
enabled: {
doc: 'Allows you to disable the usage of community packages for nodes',
format: Boolean,
default: true,
env: 'N8N_COMMUNITY_PACKAGES_ENABLED',
},
},
},
logs: {
level: {
doc: 'Log output level',

View File

@@ -75,8 +75,6 @@ type ToReturnType<T extends ConfigOptionPath> = T extends NumericPath
type ExceptionPaths = {
'queue.bull.redis': RedisOptions;
binaryDataManager: BinaryData.Config;
'nodes.exclude': string[] | undefined;
'nodes.include': string[] | undefined;
'userManagement.isInstanceOwnerSetUp': boolean;
'ui.banners.dismissed': string[] | undefined;
};

View File

@@ -88,15 +88,17 @@ export class InstanceRiskReporter implements RiskReporter {
const settings: Record<string, unknown> = {};
settings.features = {
communityPackagesEnabled: config.getEnv('nodes.communityPackages.enabled'),
communityPackagesEnabled: this.globalConfig.nodes.communityPackages.enabled,
versionNotificationsEnabled: this.globalConfig.versionNotifications.enabled,
templatesEnabled: this.globalConfig.templates.enabled,
publicApiEnabled: isApiEnabled(),
};
const { exclude, include } = this.globalConfig.nodes;
settings.nodes = {
nodesExclude: config.getEnv('nodes.exclude') ?? 'none',
nodesInclude: config.getEnv('nodes.include') ?? 'none',
nodesExclude: exclude.length === 0 ? 'none' : exclude.join(', '),
nodesInclude: include.length === 0 ? 'none' : include.join(', '),
};
settings.telemetry = {

View File

@@ -1,7 +1,6 @@
import * as path from 'path';
import glob from 'fast-glob';
import { Service } from 'typedi';
import config from '@/config';
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
import { getNodeTypes } from '@/security-audit/utils';
import {
@@ -14,12 +13,14 @@ import {
import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
import type { Risk, RiskReporter } from '@/security-audit/types';
import { CommunityPackagesService } from '@/services/communityPackages.service';
import { GlobalConfig } from '@n8n/config';
@Service()
export class NodesRiskReporter implements RiskReporter {
constructor(
private readonly loadNodesAndCredentials: LoadNodesAndCredentials,
private readonly communityPackagesService: CommunityPackagesService,
private readonly globalConfig: GlobalConfig,
) {}
async report(workflows: WorkflowEntity[]) {
@@ -85,7 +86,7 @@ export class NodesRiskReporter implements RiskReporter {
}
private async getCommunityNodeDetails() {
if (!config.getEnv('nodes.communityPackages.enabled')) return [];
if (!this.globalConfig.nodes.communityPackages.enabled) return [];
const installedPackages = await this.communityPackagesService.getAllInstalledPackages();

View File

@@ -57,7 +57,7 @@ export class FrontendService {
this.initSettings();
if (config.getEnv('nodes.communityPackages.enabled')) {
if (this.globalConfig.nodes.communityPackages.enabled) {
void import('@/services/communityPackages.service').then(({ CommunityPackagesService }) => {
this.communityPackagesService = Container.get(CommunityPackagesService);
});
@@ -154,7 +154,7 @@ export class FrontendService {
latestVersion: 1,
path: this.globalConfig.publicApi.path,
swaggerUi: {
enabled: !Container.get(GlobalConfig).publicApi.swaggerUiDisabled,
enabled: !this.globalConfig.publicApi.swaggerUiDisabled,
},
},
workflowTagsDisabled: config.getEnv('workflowTagsDisabled'),
@@ -166,7 +166,7 @@ export class FrontendService {
},
executionMode: config.getEnv('executions.mode'),
pushBackend: config.getEnv('push.backend'),
communityNodesEnabled: config.getEnv('nodes.communityPackages.enabled'),
communityNodesEnabled: this.globalConfig.nodes.communityPackages.enabled,
deployment: {
type: config.getEnv('deployment.type'),
},

View File

@@ -16,7 +16,6 @@ import {
ErrorReporterProxy as ErrorReporter,
} from 'n8n-workflow';
import config from '@/config';
import type { User } from '@db/entities/User';
import { ExecutionRepository } from '@db/repositories/execution.repository';
import { WorkflowRepository } from '@db/repositories/workflow.repository';
@@ -35,6 +34,7 @@ import { TestWebhooks } from '@/TestWebhooks';
import { Logger } from '@/Logger';
import { PermissionChecker } from '@/UserManagement/PermissionChecker';
import type { Project } from '@/databases/entities/Project';
import { GlobalConfig } from '@n8n/config';
@Service()
export class WorkflowExecutionService {
@@ -46,6 +46,7 @@ export class WorkflowExecutionService {
private readonly testWebhooks: TestWebhooks,
private readonly permissionChecker: PermissionChecker,
private readonly workflowRunner: WorkflowRunner,
private readonly globalConfig: GlobalConfig,
) {}
async runWorkflow(
@@ -230,17 +231,17 @@ export class WorkflowExecutionService {
let node: INode;
let workflowStartNode: INode | undefined;
const ERROR_TRIGGER_TYPE = config.getEnv('nodes.errorTriggerType');
const { errorTriggerType } = this.globalConfig.nodes;
for (const nodeName of Object.keys(workflowInstance.nodes)) {
node = workflowInstance.nodes[nodeName];
if (node.type === ERROR_TRIGGER_TYPE) {
if (node.type === errorTriggerType) {
workflowStartNode = node;
}
}
if (workflowStartNode === undefined) {
this.logger.error(
`Calling Error Workflow for "${workflowErrorData.workflow.id}". Could not find "${ERROR_TRIGGER_TYPE}" in workflow "${workflowId}"`,
`Calling Error Workflow for "${workflowErrorData.workflow.id}". Could not find "${errorTriggerType}" in workflow "${workflowId}"`,
);
return;
}