Skip to content

Commit

Permalink
fix(core): Fix license CLI commands showing incorrect renewal setting (
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov authored Jan 22, 2025
1 parent a39b8bd commit 024ada8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
16 changes: 15 additions & 1 deletion packages/cli/src/__tests__/license.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/license/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/license/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
14 changes: 10 additions & 4 deletions packages/cli/src/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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');
}
}

0 comments on commit 024ada8

Please sign in to comment.