mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
refactor(core): Add env var to disable Python execution (#17414)
This commit is contained in:
@@ -61,6 +61,10 @@ export class NodesConfig {
|
|||||||
@Env('NODES_ERROR_TRIGGER_TYPE')
|
@Env('NODES_ERROR_TRIGGER_TYPE')
|
||||||
errorTriggerType: string = 'n8n-nodes-base.errorTrigger';
|
errorTriggerType: string = 'n8n-nodes-base.errorTrigger';
|
||||||
|
|
||||||
|
/** Whether to enable Python execution on the Code node. */
|
||||||
|
@Env('N8N_PYTHON_ENABLED')
|
||||||
|
pythonEnabled: boolean = true;
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
communityPackages: CommunityPackagesConfig;
|
communityPackages: CommunityPackagesConfig;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ export { DeploymentConfig } from './configs/deployment.config';
|
|||||||
export { MfaConfig } from './configs/mfa.config';
|
export { MfaConfig } from './configs/mfa.config';
|
||||||
export { HiringBannerConfig } from './configs/hiring-banner.config';
|
export { HiringBannerConfig } from './configs/hiring-banner.config';
|
||||||
export { PersonalizationConfig } from './configs/personalization.config';
|
export { PersonalizationConfig } from './configs/personalization.config';
|
||||||
|
export { NodesConfig } from './configs/nodes.config';
|
||||||
|
|
||||||
const protocolSchema = z.enum(['http', 'https']);
|
const protocolSchema = z.enum(['http', 'https']);
|
||||||
|
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ describe('GlobalConfig', () => {
|
|||||||
errorTriggerType: 'n8n-nodes-base.errorTrigger',
|
errorTriggerType: 'n8n-nodes-base.errorTrigger',
|
||||||
include: [],
|
include: [],
|
||||||
exclude: [],
|
exclude: [],
|
||||||
|
pythonEnabled: true,
|
||||||
},
|
},
|
||||||
publicApi: {
|
publicApi: {
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { TaskRunnersConfig } from '@n8n/config';
|
import { NodesConfig, TaskRunnersConfig } from '@n8n/config';
|
||||||
import { Container } from '@n8n/di';
|
import { Container } from '@n8n/di';
|
||||||
import set from 'lodash/set';
|
import set from 'lodash/set';
|
||||||
import {
|
import {
|
||||||
NodeConnectionTypes,
|
NodeConnectionTypes,
|
||||||
|
UserError,
|
||||||
type CodeExecutionMode,
|
type CodeExecutionMode,
|
||||||
type CodeNodeEditorLanguage,
|
type CodeNodeEditorLanguage,
|
||||||
type IExecuteFunctions,
|
type IExecuteFunctions,
|
||||||
@@ -21,6 +22,14 @@ import { addPostExecutionWarning, standardizeOutput } from './utils';
|
|||||||
|
|
||||||
const { CODE_ENABLE_STDOUT } = process.env;
|
const { CODE_ENABLE_STDOUT } = process.env;
|
||||||
|
|
||||||
|
class PythonDisabledError extends UserError {
|
||||||
|
constructor() {
|
||||||
|
super(
|
||||||
|
'This instance disallows Python execution because it has the environment variable `N8N_PYTHON_ENABLED` set to `false`. To restore Python execution, remove this environment variable or set it to `true` and restart the instance.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class Code implements INodeType {
|
export class Code implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
displayName: 'Code',
|
displayName: 'Code',
|
||||||
@@ -96,16 +105,20 @@ export class Code implements INodeType {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async execute(this: IExecuteFunctions) {
|
async execute(this: IExecuteFunctions) {
|
||||||
const runnersConfig = Container.get(TaskRunnersConfig);
|
|
||||||
|
|
||||||
const nodeMode = this.getNodeParameter('mode', 0) as CodeExecutionMode;
|
|
||||||
const workflowMode = this.getMode();
|
|
||||||
|
|
||||||
const node = this.getNode();
|
const node = this.getNode();
|
||||||
const language: CodeNodeEditorLanguage =
|
const language: CodeNodeEditorLanguage =
|
||||||
node.typeVersion === 2
|
node.typeVersion === 2
|
||||||
? (this.getNodeParameter('language', 0) as CodeNodeEditorLanguage)
|
? (this.getNodeParameter('language', 0) as CodeNodeEditorLanguage)
|
||||||
: 'javaScript';
|
: 'javaScript';
|
||||||
|
|
||||||
|
if (language === 'python' && !Container.get(NodesConfig).pythonEnabled) {
|
||||||
|
// eslint-disable-next-line n8n-nodes-base/node-execute-block-wrong-error-thrown
|
||||||
|
throw new PythonDisabledError();
|
||||||
|
}
|
||||||
|
|
||||||
|
const runnersConfig = Container.get(TaskRunnersConfig);
|
||||||
|
const nodeMode = this.getNodeParameter('mode', 0) as CodeExecutionMode;
|
||||||
|
const workflowMode = this.getMode();
|
||||||
const codeParameterName = language === 'python' ? 'pythonCode' : 'jsCode';
|
const codeParameterName = language === 'python' ? 'pythonCode' : 'jsCode';
|
||||||
|
|
||||||
if (runnersConfig.enabled && language === 'javaScript') {
|
if (runnersConfig.enabled && language === 'javaScript') {
|
||||||
|
|||||||
Reference in New Issue
Block a user