feat(core): Add license:info command (#6047)

* feat(core): Add license:info command

* revert changes to start.ts

* revert changes to start.ts

* fix typo
This commit is contained in:
Cornelius Suermann
2023-04-21 17:10:10 +02:00
committed by GitHub
parent 54f99a7d0d
commit ab12d3e327
6 changed files with 72 additions and 39 deletions

View File

@@ -12,34 +12,6 @@ import {
} from './constants';
import { Service } from 'typedi';
async function loadCertStr(): Promise<TLicenseBlock> {
// if we have an ephemeral license, we don't want to load it from the database
const ephemeralLicense = config.get('license.cert');
if (ephemeralLicense) {
return ephemeralLicense;
}
const databaseSettings = await Db.collections.Settings.findOne({
where: {
key: SETTINGS_LICENSE_CERT_KEY,
},
});
return databaseSettings?.value ?? '';
}
async function saveCertStr(value: TLicenseBlock): Promise<void> {
// if we have an ephemeral license, we don't want to save it to the database
if (config.get('license.cert')) return;
await Db.collections.Settings.upsert(
{
key: SETTINGS_LICENSE_CERT_KEY,
value,
loadOnStartup: false,
},
['key'],
);
}
@Service()
export class License {
private logger: ILogger;
@@ -67,8 +39,8 @@ export class License {
autoRenewEnabled,
autoRenewOffset,
logger: this.logger,
loadCertStr,
saveCertStr,
loadCertStr: async () => this.loadCertStr(),
saveCertStr: async (value: TLicenseBlock) => this.saveCertStr(value),
deviceFingerprint: () => instanceId,
});
@@ -80,6 +52,34 @@ export class License {
}
}
async loadCertStr(): Promise<TLicenseBlock> {
// if we have an ephemeral license, we don't want to load it from the database
const ephemeralLicense = config.get('license.cert');
if (ephemeralLicense) {
return ephemeralLicense;
}
const databaseSettings = await Db.collections.Settings.findOne({
where: {
key: SETTINGS_LICENSE_CERT_KEY,
},
});
return databaseSettings?.value ?? '';
}
async saveCertStr(value: TLicenseBlock): Promise<void> {
// if we have an ephemeral license, we don't want to save it to the database
if (config.get('license.cert')) return;
await Db.collections.Settings.upsert(
{
key: SETTINGS_LICENSE_CERT_KEY,
value,
loadOnStartup: false,
},
['key'],
);
}
async activate(activationKey: string): Promise<void> {
if (!this.manager) {
return;
@@ -185,4 +185,12 @@ export class License {
getPlanName(): string {
return (this.getFeatureValue('planName') ?? 'Community') as string;
}
getInfo(): string {
if (!this.manager) {
return 'n/a';
}
return this.manager.toString();
}
}