Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Warn on unknown N8N env vars #9279

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/cli/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ config.validate({
const userManagement = config.get('userManagement');
if (userManagement.jwtRefreshTimeoutHours >= userManagement.jwtSessionDurationHours) {
console.warn(
'N8N_USER_MANAGEMENT_JWT_REFRESH_TIMEOUT_HOURS needs to smaller than N8N_USER_MANAGEMENT_JWT_DURATION_HOURS. Setting N8N_USER_MANAGEMENT_JWT_REFRESH_TIMEOUT_HOURS to 0 for now.',
'N8N_USER_MANAGEMENT_JWT_REFRESH_TIMEOUT_HOURS needs to be smaller than N8N_USER_MANAGEMENT_JWT_DURATION_HOURS. Setting N8N_USER_MANAGEMENT_JWT_REFRESH_TIMEOUT_HOURS to 0 for now.',
);

config.set('userManagement.jwtRefreshTimeoutHours', 0);
}

import colors from 'picocolors';
import { findSchemaEnvVars } from './utils';

const executionProcess = config.getEnv('executions.process');
if (executionProcess) {
console.error(
Expand All @@ -95,6 +97,18 @@ if (executionProcess === 'own') {
process.exit(-1);
}

const schemaEnvVars = findSchemaEnvVars(schema);
const processN8nEnvVars = Object.keys(process.env).filter((env) => env.startsWith('N8N'));
const unknownN8nEnvVars = processN8nEnvVars.filter((i) => !schemaEnvVars.includes(i));

if (unknownN8nEnvVars.length > 0) {
const _var = unknownN8nEnvVars.length > 1 ? 'variables' : 'variable';
console.warn(
colors.bold(colors.yellow(`Unknown N8N-prefixed environment ${_var} detected:`)),
unknownN8nEnvVars.join(', '),
);
}

setGlobalState({
defaultTimezone: config.getEnv('generic.timezone'),
});
Expand Down
20 changes: 20 additions & 0 deletions packages/cli/src/config/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,23 @@ export const ensureStringArray = (values: string[], { env }: SchemaObj<string>)
if (typeof value !== 'string') throw new NotStringArrayError(env);
}
};

export function findSchemaEnvVars(schema: Record<string, unknown>) {
const envVars: string[] = [];

const traverse = (obj: Record<string, unknown>) => {
for (const key in obj) {
const value = obj[key] as Record<string, unknown> | string;

if (typeof value === 'object') {
traverse(value);
} else if (typeof value === 'string' && key === 'env') {
envVars.push(value);
}
}
};

traverse(schema);
Comment on lines +18 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we create a function and call it right away? Would something break if we lifted the body of traverse into findSchemaEnvVars' body?


return envVars;
}