Skip to content

Commit

Permalink
chore: Bump license-sdk to v2.16.1 (no-changelog) (#13351)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomi Turtiainen <[email protected]>
  • Loading branch information
csuermann and tomi authored Feb 19, 2025
1 parent c3dc66e commit daa1fe9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"@n8n/task-runner": "workspace:*",
"@n8n/typeorm": "0.3.20-12",
"@n8n_io/ai-assistant-sdk": "1.13.0",
"@n8n_io/license-sdk": "2.16.0",
"@n8n_io/license-sdk": "2.16.1",
"@oclif/core": "4.0.7",
"@rudderstack/rudder-sdk-node": "2.0.9",
"@sentry/node": "catalog:",
Expand Down
84 changes: 53 additions & 31 deletions packages/cli/src/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ export class License {
});

await this.manager.initialize();

const features = this.manager.getFeatures();
this.checkIsLicensedForMultiMain(features);
this.checkIsLicensedForBinaryDataS3(features);

this.logger.debug('License initialized');
} catch (error: unknown) {
if (error instanceof Error) {
Expand All @@ -129,44 +134,20 @@ export class License {
async onFeatureChange(_features: TFeatures): Promise<void> {
this.logger.debug('License feature change detected', _features);

if (config.getEnv('executions.mode') === 'queue' && this.globalConfig.multiMainSetup.enabled) {
const isMultiMainLicensed =
(_features[LICENSE_FEATURES.MULTIPLE_MAIN_INSTANCES] as boolean | undefined) ?? false;

this.instanceSettings.setMultiMainLicensed(isMultiMainLicensed);
this.checkIsLicensedForMultiMain(_features);
this.checkIsLicensedForBinaryDataS3(_features);

if (this.instanceSettings.isMultiMain && !this.instanceSettings.isLeader) {
this.logger
.scoped(['scaling', 'multi-main-setup', 'license'])
.debug('Instance is not leader, skipping sending of "reload-license" command...');
return;
}

if (this.globalConfig.multiMainSetup.enabled && !isMultiMainLicensed) {
this.logger
.scoped(['scaling', 'multi-main-setup', 'license'])
.debug(
'License changed with no support for multi-main setup - no new followers will be allowed to init. To restore multi-main setup, please upgrade to a license that supports this feature.',
);
}
if (this.instanceSettings.isMultiMain && !this.instanceSettings.isLeader) {
this.logger
.scoped(['scaling', 'multi-main-setup', 'license'])
.debug('Instance is not leader, skipping sending of "reload-license" command...');
return;
}

if (config.getEnv('executions.mode') === 'queue') {
const { Publisher } = await import('@/scaling/pubsub/publisher.service');
await Container.get(Publisher).publishCommand({ command: 'reload-license' });
}

const isS3Selected = config.getEnv('binaryDataManager.mode') === 's3';
const isS3Available = config.getEnv('binaryDataManager.availableModes').includes('s3');
const isS3Licensed = _features['feat:binaryDataS3'];

if (isS3Selected && isS3Available && !isS3Licensed) {
this.logger.debug(
'License changed with no support for external storage - blocking writes on object store. To restore writes, please upgrade to a license that supports this feature.',
);

Container.get(ObjectStoreService).setReadonly(true);
}
}

async saveCertStr(value: TLicenseBlock): Promise<void> {
Expand Down Expand Up @@ -407,4 +388,45 @@ export class License {
await this.init({ forceRecreate: true });
this.logger.debug('License reinitialized');
}

/**
* Ensures that the instance is licensed for multi-main setup if multi-main mode is enabled
*/
private checkIsLicensedForMultiMain(features: TFeatures) {
const isMultiMainEnabled =
config.getEnv('executions.mode') === 'queue' && this.globalConfig.multiMainSetup.enabled;
if (!isMultiMainEnabled) {
return;
}

const isMultiMainLicensed =
(features[LICENSE_FEATURES.MULTIPLE_MAIN_INSTANCES] as boolean | undefined) ?? false;

this.instanceSettings.setMultiMainLicensed(isMultiMainLicensed);

if (!isMultiMainLicensed) {
this.logger
.scoped(['scaling', 'multi-main-setup', 'license'])
.debug(
'License changed with no support for multi-main setup - no new followers will be allowed to init. To restore multi-main setup, please upgrade to a license that supports this feature.',
);
}
}

/**
* Ensures that the instance is licensed for binary data S3 if S3 is selected and available
*/
private checkIsLicensedForBinaryDataS3(features: TFeatures) {
const isS3Selected = config.getEnv('binaryDataManager.mode') === 's3';
const isS3Available = config.getEnv('binaryDataManager.availableModes').includes('s3');
const isS3Licensed = features['feat:binaryDataS3'];

if (isS3Selected && isS3Available && !isS3Licensed) {
this.logger.debug(
'License changed with no support for external storage - blocking writes on object store. To restore writes, please upgrade to a license that supports this feature.',
);

Container.get(ObjectStoreService).setReadonly(true);
}
}
}
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit daa1fe9

Please sign in to comment.