Check license to typescript (#52955)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Tim Sullivan 2020-01-06 13:29:13 -07:00 committed by GitHub
parent 368a894bd2
commit c9c80845d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 15 deletions

View file

@ -94,7 +94,7 @@ export const reporting = (kibana: any) => {
const { xpack_main: xpackMainPlugin } = server.plugins;
mirrorPluginStatus(xpackMainPlugin, this);
const checkLicense = checkLicenseFactory(exportTypesRegistry);
xpackMainPlugin.status.once('green', () => {
(xpackMainPlugin as any).status.once('green', () => {
// Register a function that is called whenever the xpack info changes,
// to re-compute the license check results for this plugin
xpackMainPlugin.info.feature(this.id).registerLicenseCheckResultsGenerator(checkLicense);

View file

@ -4,19 +4,31 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { XPackInfo } from '../../../xpack_main/server/lib/xpack_info';
import { XPackInfoLicense } from '../../../xpack_main/server/lib/xpack_info_license';
import { ExportTypesRegistry, ExportTypeDefinition } from '../../types';
interface LicenseCheckResult {
showLinks: boolean;
enableLinks: boolean;
message?: string;
}
const messages = {
getUnavailable: () => {
return 'You cannot use Reporting because license information is not available at this time.';
},
getExpired: license => {
getExpired: (license: XPackInfoLicense) => {
return `You cannot use Reporting because your ${license.getType()} license has expired.`;
},
};
const makeManagementFeature = exportTypes => {
const makeManagementFeature = (
exportTypes: Array<ExportTypeDefinition<unknown, unknown, unknown, unknown>>
) => {
return {
id: 'management',
checkLicense: license => {
checkLicense: (license: XPackInfoLicense | null) => {
if (!license) {
return {
showLinks: true,
@ -46,10 +58,12 @@ const makeManagementFeature = exportTypes => {
};
};
const makeExportTypeFeature = exportType => {
const makeExportTypeFeature = (
exportType: ExportTypeDefinition<unknown, unknown, unknown, unknown>
) => {
return {
id: exportType.id,
checkLicense: license => {
checkLicense: (license: XPackInfoLicense | null) => {
if (!license) {
return {
showLinks: true,
@ -84,13 +98,9 @@ const makeExportTypeFeature = exportType => {
};
};
export function checkLicenseFactory(exportTypesRegistry) {
return function checkLicense(xpackLicenseInfo) {
const license =
xpackLicenseInfo === null || !xpackLicenseInfo.isAvailable()
? null
: xpackLicenseInfo.license;
export function checkLicenseFactory(exportTypesRegistry: ExportTypesRegistry) {
return function checkLicense(xpackInfo: XPackInfo) {
const license = xpackInfo === null || !xpackInfo.isAvailable() ? null : xpackInfo.license;
const exportTypes = Array.from(exportTypesRegistry.getAll());
const reportingFeatures = [
...exportTypes.map(makeExportTypeFeature),
@ -100,6 +110,6 @@ export function checkLicenseFactory(exportTypesRegistry) {
return reportingFeatures.reduce((result, feature) => {
result[feature.id] = feature.checkLicense(license);
return result;
}, {});
}, {} as Record<string, LicenseCheckResult>);
};
}

View file

@ -5,7 +5,6 @@
*/
export { getExportTypesRegistry } from './export_types_registry';
// @ts-ignore untyped module
export { checkLicenseFactory } from './check_license';
export { LevelLogger } from './level_logger';
export { cryptoFactory } from './crypto';