mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
fix(core): Initialize License and LDAP in the correct order (#5673)
This commit is contained in:
parent
5c4343b828
commit
90afa5e55f
|
@ -130,12 +130,16 @@ import * as WorkflowExecuteAdditionalData from '@/WorkflowExecuteAdditionalData'
|
||||||
import { toHttpNodeParameters } from '@/CurlConverterHelper';
|
import { toHttpNodeParameters } from '@/CurlConverterHelper';
|
||||||
import { eventBusRouter } from '@/eventbus/eventBusRoutes';
|
import { eventBusRouter } from '@/eventbus/eventBusRoutes';
|
||||||
import { isLogStreamingEnabled } from '@/eventbus/MessageEventBus/MessageEventBusHelper';
|
import { isLogStreamingEnabled } from '@/eventbus/MessageEventBus/MessageEventBusHelper';
|
||||||
import { getLicense } from '@/License';
|
|
||||||
import { licenseController } from './license/license.controller';
|
import { licenseController } from './license/license.controller';
|
||||||
import { Push, setupPushServer, setupPushHandler } from '@/push';
|
import { Push, setupPushServer, setupPushHandler } from '@/push';
|
||||||
import { setupAuthMiddlewares } from './middlewares';
|
import { setupAuthMiddlewares } from './middlewares';
|
||||||
import { initEvents } from './events';
|
import { initEvents } from './events';
|
||||||
import { getLdapLoginLabel, isLdapEnabled, isLdapLoginEnabled } from './Ldap/helpers';
|
import {
|
||||||
|
getLdapLoginLabel,
|
||||||
|
handleLdapInit,
|
||||||
|
isLdapEnabled,
|
||||||
|
isLdapLoginEnabled,
|
||||||
|
} from './Ldap/helpers';
|
||||||
import { AbstractServer } from './AbstractServer';
|
import { AbstractServer } from './AbstractServer';
|
||||||
import { configureMetrics } from './metrics';
|
import { configureMetrics } from './metrics';
|
||||||
import { setupBasicAuth } from './middlewares/basicAuth';
|
import { setupBasicAuth } from './middlewares/basicAuth';
|
||||||
|
@ -357,20 +361,6 @@ class Server extends AbstractServer {
|
||||||
return this.frontendSettings;
|
return this.frontendSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
async initLicense(): Promise<void> {
|
|
||||||
const license = getLicense();
|
|
||||||
await license.init(this.frontendSettings.instanceId);
|
|
||||||
|
|
||||||
const activationKey = config.getEnv('license.activationKey');
|
|
||||||
if (activationKey) {
|
|
||||||
try {
|
|
||||||
await license.activate(activationKey);
|
|
||||||
} catch (e) {
|
|
||||||
LoggerProxy.error('Could not activate license', e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private registerControllers(ignoredEndpoints: Readonly<string[]>) {
|
private registerControllers(ignoredEndpoints: Readonly<string[]>) {
|
||||||
const { app, externalHooks, activeWorkflowRunner, nodeTypes } = this;
|
const { app, externalHooks, activeWorkflowRunner, nodeTypes } = this;
|
||||||
const repositories = Db.collections;
|
const repositories = Db.collections;
|
||||||
|
@ -428,7 +418,6 @@ class Server extends AbstractServer {
|
||||||
|
|
||||||
await this.externalHooks.run('frontend.settings', [this.frontendSettings]);
|
await this.externalHooks.run('frontend.settings', [this.frontendSettings]);
|
||||||
|
|
||||||
await this.initLicense();
|
|
||||||
await this.postHog.init(this.frontendSettings.instanceId);
|
await this.postHog.init(this.frontendSettings.instanceId);
|
||||||
|
|
||||||
const publicApiEndpoint = config.getEnv('publicApi.path');
|
const publicApiEndpoint = config.getEnv('publicApi.path');
|
||||||
|
@ -490,9 +479,8 @@ class Server extends AbstractServer {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
// ----------------------------------------
|
await handleLdapInit();
|
||||||
// User Management
|
|
||||||
// ----------------------------------------
|
|
||||||
this.registerControllers(ignoredEndpoints);
|
this.registerControllers(ignoredEndpoints);
|
||||||
|
|
||||||
this.app.use(`/${this.restEndpoint}/credentials`, credentialsController);
|
this.app.use(`/${this.restEndpoint}/credentials`, credentialsController);
|
||||||
|
|
|
@ -34,6 +34,8 @@ export abstract class BaseCommand extends Command {
|
||||||
|
|
||||||
protected userSettings: IUserSettings;
|
protected userSettings: IUserSettings;
|
||||||
|
|
||||||
|
protected instanceId: string;
|
||||||
|
|
||||||
async init(): Promise<void> {
|
async init(): Promise<void> {
|
||||||
await initErrorHandling();
|
await initErrorHandling();
|
||||||
|
|
||||||
|
@ -49,9 +51,9 @@ export abstract class BaseCommand extends Command {
|
||||||
const credentialTypes = Container.get(CredentialTypes);
|
const credentialTypes = Container.get(CredentialTypes);
|
||||||
CredentialsOverwrites(credentialTypes);
|
CredentialsOverwrites(credentialTypes);
|
||||||
|
|
||||||
const instanceId = this.userSettings.instanceId ?? '';
|
this.instanceId = this.userSettings.instanceId ?? '';
|
||||||
await Container.get(PostHogClient).init(instanceId);
|
await Container.get(PostHogClient).init(this.instanceId);
|
||||||
await Container.get(InternalHooks).init(instanceId);
|
await Container.get(InternalHooks).init(this.instanceId);
|
||||||
|
|
||||||
await Db.init().catch(async (error: Error) =>
|
await Db.init().catch(async (error: Error) =>
|
||||||
this.exitWithCrash('There was an error initializing DB', error),
|
this.exitWithCrash('There was an error initializing DB', error),
|
||||||
|
|
|
@ -24,11 +24,11 @@ import * as GenericHelpers from '@/GenericHelpers';
|
||||||
import * as Server from '@/Server';
|
import * as Server from '@/Server';
|
||||||
import { TestWebhooks } from '@/TestWebhooks';
|
import { TestWebhooks } from '@/TestWebhooks';
|
||||||
import { getAllInstalledPackages } from '@/CommunityNodes/packageModel';
|
import { getAllInstalledPackages } from '@/CommunityNodes/packageModel';
|
||||||
import { handleLdapInit } from '@/Ldap/helpers';
|
|
||||||
import { EDITOR_UI_DIST_DIR, GENERATED_STATIC_DIR } from '@/constants';
|
import { EDITOR_UI_DIST_DIR, GENERATED_STATIC_DIR } from '@/constants';
|
||||||
import { eventBus } from '@/eventbus';
|
import { eventBus } from '@/eventbus';
|
||||||
import { BaseCommand } from './BaseCommand';
|
import { BaseCommand } from './BaseCommand';
|
||||||
import { InternalHooks } from '@/InternalHooks';
|
import { InternalHooks } from '@/InternalHooks';
|
||||||
|
import { getLicense } from '@/License';
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
|
||||||
const open = require('open');
|
const open = require('open');
|
||||||
|
@ -182,11 +182,26 @@ export class Start extends BaseCommand {
|
||||||
await Promise.all(files.map(compileFile));
|
await Promise.all(files.map(compileFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async initLicense(): Promise<void> {
|
||||||
|
const license = getLicense();
|
||||||
|
await license.init(this.instanceId);
|
||||||
|
|
||||||
|
const activationKey = config.getEnv('license.activationKey');
|
||||||
|
if (activationKey) {
|
||||||
|
try {
|
||||||
|
await license.activate(activationKey);
|
||||||
|
} catch (e) {
|
||||||
|
LoggerProxy.error('Could not activate license', e as Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
await this.initCrashJournal();
|
await this.initCrashJournal();
|
||||||
await super.init();
|
await super.init();
|
||||||
this.logger.info('Initializing n8n process');
|
this.logger.info('Initializing n8n process');
|
||||||
|
|
||||||
|
await this.initLicense();
|
||||||
await this.initBinaryManager();
|
await this.initBinaryManager();
|
||||||
await this.initExternalHooks();
|
await this.initExternalHooks();
|
||||||
|
|
||||||
|
@ -326,8 +341,6 @@ export class Start extends BaseCommand {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await handleLdapInit();
|
|
||||||
|
|
||||||
await Server.start();
|
await Server.start();
|
||||||
|
|
||||||
// Start to get active workflows and run their triggers
|
// Start to get active workflows and run their triggers
|
||||||
|
|
Loading…
Reference in a new issue