mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
* Prefix license status constants and move them into a constants directory. * Add constants for license types.
This commit is contained in:
parent
9ee0b43d58
commit
26541a16fb
10 changed files with 86 additions and 31 deletions
12
x-pack/common/constants/index.ts
Normal file
12
x-pack/common/constants/index.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
export {
|
||||
LICENSE_STATUS_UNAVAILABLE,
|
||||
LICENSE_STATUS_INVALID,
|
||||
LICENSE_STATUS_EXPIRED,
|
||||
LICENSE_STATUS_VALID,
|
||||
} from './license_status';
|
10
x-pack/common/constants/license_status.ts
Normal file
10
x-pack/common/constants/license_status.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
export const LICENSE_STATUS_UNAVAILABLE = 'UNAVAILABLE';
|
||||
export const LICENSE_STATUS_INVALID = 'INVALID';
|
||||
export const LICENSE_STATUS_EXPIRED = 'EXPIRED';
|
||||
export const LICENSE_STATUS_VALID = 'VALID';
|
|
@ -6,7 +6,12 @@
|
|||
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { RANKED_LICENSE_TYPES } from '../constants';
|
||||
import { LICENSE_STATUS } from '../../../common/constants';
|
||||
import {
|
||||
LICENSE_STATUS_UNAVAILABLE,
|
||||
LICENSE_STATUS_INVALID,
|
||||
LICENSE_STATUS_EXPIRED,
|
||||
LICENSE_STATUS_VALID,
|
||||
} from '../../../common/constants';
|
||||
|
||||
export function checkLicense(pluginName, minimumLicenseRequired, xpackLicenseInfo) {
|
||||
if(!RANKED_LICENSE_TYPES.includes(minimumLicenseRequired)) {
|
||||
|
@ -17,7 +22,7 @@ export function checkLicense(pluginName, minimumLicenseRequired, xpackLicenseInf
|
|||
// from Elasticsearch, assume worst case and disable
|
||||
if (!xpackLicenseInfo || !xpackLicenseInfo.isAvailable()) {
|
||||
return {
|
||||
status: LICENSE_STATUS.UNAVAILABLE,
|
||||
status: LICENSE_STATUS_UNAVAILABLE,
|
||||
message: i18n.translate(
|
||||
'xpack.server.checkLicense.errorUnavailableMessage',
|
||||
{
|
||||
|
@ -36,7 +41,7 @@ export function checkLicense(pluginName, minimumLicenseRequired, xpackLicenseInf
|
|||
// License is not valid
|
||||
if (!isLicenseModeValid) {
|
||||
return {
|
||||
status: LICENSE_STATUS.INVALID,
|
||||
status: LICENSE_STATUS_INVALID,
|
||||
message: i18n.translate(
|
||||
'xpack.server.checkLicense.errorUnsupportedMessage',
|
||||
{
|
||||
|
@ -50,7 +55,7 @@ export function checkLicense(pluginName, minimumLicenseRequired, xpackLicenseInf
|
|||
// License is valid but not active
|
||||
if (!isLicenseActive) {
|
||||
return {
|
||||
status: LICENSE_STATUS.EXPIRED,
|
||||
status: LICENSE_STATUS_EXPIRED,
|
||||
message: i18n.translate(
|
||||
'xpack.server.checkLicense.errorExpiredMessage',
|
||||
{
|
||||
|
@ -63,6 +68,6 @@ export function checkLicense(pluginName, minimumLicenseRequired, xpackLicenseInf
|
|||
|
||||
// License is valid and active
|
||||
return {
|
||||
status: LICENSE_STATUS.VALID,
|
||||
status: LICENSE_STATUS_VALID,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -6,7 +6,11 @@
|
|||
|
||||
import { set } from 'lodash';
|
||||
import { checkLicense } from './check_license';
|
||||
import { LICENSE_STATUS } from '../../../common/constants';
|
||||
import {
|
||||
LICENSE_STATUS_UNAVAILABLE,
|
||||
LICENSE_STATUS_EXPIRED,
|
||||
LICENSE_STATUS_VALID,
|
||||
} from '../../../common/constants';
|
||||
|
||||
describe('check_license', function () {
|
||||
|
||||
|
@ -19,7 +23,7 @@ describe('check_license', function () {
|
|||
beforeEach(() => mockLicenseInfo = undefined);
|
||||
|
||||
it('should set status to unavailable', () => {
|
||||
expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(LICENSE_STATUS.UNAVAILABLE);
|
||||
expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(LICENSE_STATUS_UNAVAILABLE);
|
||||
});
|
||||
|
||||
it('should set a message', () => {
|
||||
|
@ -31,7 +35,7 @@ describe('check_license', function () {
|
|||
beforeEach(() => mockLicenseInfo.isAvailable = () => false);
|
||||
|
||||
it('should set status to unavailable', () => {
|
||||
expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(LICENSE_STATUS.UNAVAILABLE);
|
||||
expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(LICENSE_STATUS_UNAVAILABLE);
|
||||
});
|
||||
|
||||
it('should set a message', () => {
|
||||
|
@ -52,7 +56,7 @@ describe('check_license', function () {
|
|||
beforeEach(() => set(mockLicenseInfo, 'license.isActive', () => true));
|
||||
|
||||
it('should set status to valid', () => {
|
||||
expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(LICENSE_STATUS.VALID);
|
||||
expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(LICENSE_STATUS_VALID);
|
||||
});
|
||||
|
||||
it('should not set a message', () => {
|
||||
|
@ -64,7 +68,7 @@ describe('check_license', function () {
|
|||
beforeEach(() => set(mockLicenseInfo, 'license.isActive', () => false));
|
||||
|
||||
it('should set status to inactive', () => {
|
||||
expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(LICENSE_STATUS.EXPIRED);
|
||||
expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(LICENSE_STATUS_EXPIRED);
|
||||
});
|
||||
|
||||
it('should set a message', () => {
|
||||
|
@ -80,7 +84,7 @@ describe('check_license', function () {
|
|||
beforeEach(() => set(mockLicenseInfo, 'license.isActive', () => true));
|
||||
|
||||
it('should set status to valid', () => {
|
||||
expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(LICENSE_STATUS.VALID);
|
||||
expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(LICENSE_STATUS_VALID);
|
||||
});
|
||||
|
||||
it('should not set a message', () => {
|
||||
|
@ -92,7 +96,7 @@ describe('check_license', function () {
|
|||
beforeEach(() => set(mockLicenseInfo, 'license.isActive', () => false));
|
||||
|
||||
it('should set status to inactive', () => {
|
||||
expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(LICENSE_STATUS.EXPIRED);
|
||||
expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(LICENSE_STATUS_EXPIRED);
|
||||
});
|
||||
|
||||
it('should set a message', () => {
|
||||
|
|
|
@ -4,9 +4,4 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
export const LICENSE_STATUS = {
|
||||
UNAVAILABLE: 'UNAVAILABLE',
|
||||
INVALID: 'INVALID',
|
||||
EXPIRED: 'EXPIRED',
|
||||
VALID: 'VALID',
|
||||
};
|
||||
export const XPACK_DEFAULT_ADMIN_EMAIL_UI_SETTING = 'xPack:defaultAdminEmail';
|
16
x-pack/server/lib/constants/index.ts
Normal file
16
x-pack/server/lib/constants/index.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
export { XPACK_DEFAULT_ADMIN_EMAIL_UI_SETTING } from './admin';
|
||||
export { XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS } from './xpack_info';
|
||||
export {
|
||||
LICENSE_TYPE_BASIC,
|
||||
LICENSE_TYPE_STANDARD,
|
||||
LICENSE_TYPE_GOLD,
|
||||
LICENSE_TYPE_PLATINUM,
|
||||
LICENSE_TYPE_TRIAL,
|
||||
RANKED_LICENSE_TYPES,
|
||||
} from './license';
|
21
x-pack/server/lib/constants/license.ts
Normal file
21
x-pack/server/lib/constants/license.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
export const LICENSE_TYPE_BASIC = 'basic';
|
||||
export const LICENSE_TYPE_STANDARD = 'standard';
|
||||
export const LICENSE_TYPE_GOLD = 'gold';
|
||||
export const LICENSE_TYPE_PLATINUM = 'platinum';
|
||||
export const LICENSE_TYPE_TRIAL = 'trial';
|
||||
|
||||
// These are ordered from least featureful to most featureful, so we can assume that someone holding
|
||||
// a license at a particular index cannot access any features unlocked by the licenses that follow it.
|
||||
export const RANKED_LICENSE_TYPES = [
|
||||
LICENSE_TYPE_BASIC,
|
||||
LICENSE_TYPE_STANDARD,
|
||||
LICENSE_TYPE_GOLD,
|
||||
LICENSE_TYPE_PLATINUM,
|
||||
LICENSE_TYPE_TRIAL,
|
||||
];
|
|
@ -4,12 +4,4 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
export const XPACK_DEFAULT_ADMIN_EMAIL_UI_SETTING = 'xPack:defaultAdminEmail';
|
||||
export const XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS = 30001; // 30 seconds
|
||||
export const RANKED_LICENSE_TYPES = [
|
||||
'basic',
|
||||
'standard',
|
||||
'gold',
|
||||
'platinum',
|
||||
'trial',
|
||||
];
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import expect from 'expect.js';
|
||||
import { licensePreRoutingFactory } from '../license_pre_routing_factory';
|
||||
import { LICENSE_STATUS } from '../../../../../common/constants';
|
||||
import { LICENSE_STATUS_INVALID, LICENSE_STATUS_VALID } from '../../../../../common/constants';
|
||||
|
||||
describe('license_pre_routing_factory', () => {
|
||||
describe('#reportingFeaturePreRoutingFactory', () => {
|
||||
|
@ -37,7 +37,7 @@ describe('license_pre_routing_factory', () => {
|
|||
describe('status is invalid', () => {
|
||||
beforeEach(() => {
|
||||
mockLicenseCheckResults = {
|
||||
status: LICENSE_STATUS.INVALID
|
||||
status: LICENSE_STATUS_INVALID
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -55,7 +55,7 @@ describe('license_pre_routing_factory', () => {
|
|||
describe('status is valid', () => {
|
||||
beforeEach(() => {
|
||||
mockLicenseCheckResults = {
|
||||
status: LICENSE_STATUS.VALID
|
||||
status: LICENSE_STATUS_VALID
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
|
||||
import { once } from 'lodash';
|
||||
import { wrapCustomError } from '../error_wrappers';
|
||||
import { LICENSE_STATUS } from '../../../../common/constants';
|
||||
import { LICENSE_STATUS_VALID } from '../../../../common/constants';
|
||||
|
||||
export const licensePreRoutingFactory = (server, pluginId) => {
|
||||
const licensePreRouting = () => {
|
||||
// License checking and enable/disable logic
|
||||
const xpackMainPlugin = server.plugins.xpack_main;
|
||||
const licenseCheckResults = xpackMainPlugin.info.feature(pluginId).getLicenseCheckResults();
|
||||
if (licenseCheckResults.status !== LICENSE_STATUS.VALID) {
|
||||
if (licenseCheckResults.status !== LICENSE_STATUS_VALID) {
|
||||
const error = new Error(licenseCheckResults.message);
|
||||
const statusCode = 403;
|
||||
throw wrapCustomError(error, statusCode);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue