mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
refactor(core): Add env var to disable Python execution (#17414)
This commit is contained in:
@@ -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