mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 09:36:44 +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')
|
||||
errorTriggerType: string = 'n8n-nodes-base.errorTrigger';
|
||||
|
||||
/** Whether to enable Python execution on the Code node. */
|
||||
@Env('N8N_PYTHON_ENABLED')
|
||||
pythonEnabled: boolean = true;
|
||||
|
||||
@Nested
|
||||
communityPackages: CommunityPackagesConfig;
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ export { DeploymentConfig } from './configs/deployment.config';
|
||||
export { MfaConfig } from './configs/mfa.config';
|
||||
export { HiringBannerConfig } from './configs/hiring-banner.config';
|
||||
export { PersonalizationConfig } from './configs/personalization.config';
|
||||
export { NodesConfig } from './configs/nodes.config';
|
||||
|
||||
const protocolSchema = z.enum(['http', 'https']);
|
||||
|
||||
|
||||
@@ -149,6 +149,7 @@ describe('GlobalConfig', () => {
|
||||
errorTriggerType: 'n8n-nodes-base.errorTrigger',
|
||||
include: [],
|
||||
exclude: [],
|
||||
pythonEnabled: true,
|
||||
},
|
||||
publicApi: {
|
||||
disabled: false,
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { TaskRunnersConfig } from '@n8n/config';
|
||||
import { NodesConfig, TaskRunnersConfig } from '@n8n/config';
|
||||
import { Container } from '@n8n/di';
|
||||
import set from 'lodash/set';
|
||||
import {
|
||||
NodeConnectionTypes,
|
||||
UserError,
|
||||
type CodeExecutionMode,
|
||||
type CodeNodeEditorLanguage,
|
||||
type IExecuteFunctions,
|
||||
@@ -21,6 +22,14 @@ import { addPostExecutionWarning, standardizeOutput } from './utils';
|
||||
|
||||
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 {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Code',
|
||||
@@ -96,16 +105,20 @@ export class Code implements INodeType {
|
||||
};
|
||||
|
||||
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 language: CodeNodeEditorLanguage =
|
||||
node.typeVersion === 2
|
||||
? (this.getNodeParameter('language', 0) as CodeNodeEditorLanguage)
|
||||
: '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';
|
||||
|
||||
if (runnersConfig.enabled && language === 'javaScript') {
|
||||
|
||||
Reference in New Issue
Block a user