fix(core): Fix license CLI commands showing incorrect renewal setting (#12759)
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions

This commit is contained in:
Iván Ovejero 2025-01-22 09:00:39 +01:00 committed by GitHub
parent a39b8bd32b
commit 024ada822c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 7 deletions

View file

@ -251,6 +251,20 @@ describe('License', () => {
expect(LicenseManager).toHaveBeenCalledWith(expect.objectContaining(expectedRenewalSettings));
});
it('when CLI command with N8N_LICENSE_AUTO_RENEW_ENABLED=true, should enable renewal', async () => {
const globalConfig = mock<GlobalConfig>({
license: { ...licenseConfig, autoRenewalEnabled: true },
});
await new License(mockLogger(), mock(), mock(), mock(), globalConfig).init({
isCli: true,
});
expect(LicenseManager).toHaveBeenCalledWith(
expect.objectContaining({ autoRenewEnabled: true, renewOnInit: true }),
);
});
});
describe('reinit', () => {
@ -262,7 +276,7 @@ describe('License', () => {
await license.reinit();
expect(initSpy).toHaveBeenCalledWith(true);
expect(initSpy).toHaveBeenCalledWith({ forceRecreate: true });
expect(LicenseManager.prototype.reset).toHaveBeenCalled();
expect(LicenseManager.prototype.initialize).toHaveBeenCalled();

View file

@ -16,7 +16,7 @@ export class ClearLicenseCommand extends BaseCommand {
// Attempt to invoke shutdown() to force any floating entitlements to be released
const license = Container.get(License);
await license.init();
await license.init({ isCli: true });
try {
await license.shutdown();
} catch {

View file

@ -11,7 +11,7 @@ export class LicenseInfoCommand extends BaseCommand {
async run() {
const license = Container.get(License);
await license.init();
await license.init({ isCli: true });
this.logger.info('Printing license information:\n' + license.getInfo());
}

View file

@ -43,7 +43,10 @@ export class License {
this.logger = this.logger.scoped('license');
}
async init(forceRecreate = false) {
async init({
forceRecreate = false,
isCli = false,
}: { forceRecreate?: boolean; isCli?: boolean } = {}) {
if (this.manager && !forceRecreate) {
this.logger.warn('License manager already initialized or shutting down');
return;
@ -73,10 +76,13 @@ export class License {
const { isLeader } = this.instanceSettings;
const { autoRenewalEnabled } = this.globalConfig.license;
const eligibleToRenew = isCli || isLeader;
const shouldRenew = isLeader && autoRenewalEnabled;
const shouldRenew = eligibleToRenew && autoRenewalEnabled;
if (isLeader && !autoRenewalEnabled) this.logger.warn(LICENSE_RENEWAL_DISABLED_WARNING);
if (eligibleToRenew && !autoRenewalEnabled) {
this.logger.warn(LICENSE_RENEWAL_DISABLED_WARNING);
}
try {
this.manager = new LicenseManager({
@ -390,7 +396,7 @@ export class License {
async reinit() {
this.manager?.reset();
await this.init(true);
await this.init({ forceRecreate: true });
this.logger.debug('License reinitialized');
}
}