Skip to content

Commit

Permalink
Move license constants from /server to /common (#32723)
Browse files Browse the repository at this point in the history
* Move license constants to /common

* Fix export

* Use constant for required license type

* Remove OSS from license types
  • Loading branch information
jen-huang authored Mar 8, 2019
1 parent a854a11 commit 7afd091
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 13 deletions.
10 changes: 10 additions & 0 deletions x-pack/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@ export {
LICENSE_STATUS_EXPIRED,
LICENSE_STATUS_VALID,
} from './license_status';

export {
LICENSE_TYPE_BASIC,
LICENSE_TYPE_STANDARD,
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
LICENSE_TYPE_TRIAL,
RANKED_LICENSE_TYPES,
LicenseType,
} from './license_types';
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ export const LICENSE_TYPE_GOLD = 'gold';
export const LICENSE_TYPE_PLATINUM = 'platinum';
export const LICENSE_TYPE_TRIAL = 'trial';

export type LicenseType =
| typeof LICENSE_TYPE_BASIC
| typeof LICENSE_TYPE_STANDARD
| typeof LICENSE_TYPE_GOLD
| typeof LICENSE_TYPE_PLATINUM
| typeof LICENSE_TYPE_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 = [
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/index_management/common/constants/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
*/

import { i18n } from '@kbn/i18n';
import { LICENSE_TYPE_BASIC } from '../../../../common/constants';

export const PLUGIN = {
ID: 'index_management',
NAME: i18n.translate('xpack.idxMgmt.appTitle', {
defaultMessage: 'Index Management'
}),
MINIMUM_LICENSE_REQUIRED: 'basic',
MINIMUM_LICENSE_REQUIRED: LICENSE_TYPE_BASIC,
};
3 changes: 2 additions & 1 deletion x-pack/plugins/license_management/common/constants/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
*/

import { i18n } from '@kbn/i18n';
import { LICENSE_TYPE_BASIC } from '../../../../common/constants';

export const PLUGIN = {
ID: 'license_management',
NAME: i18n.translate('xpack.licenseMgmt.managementSectionDisplayName', {
defaultMessage: 'License Management',
}),
MINIMUM_LICENSE_REQUIRED: 'basic',
MINIMUM_LICENSE_REQUIRED: LICENSE_TYPE_BASIC,
};
2 changes: 1 addition & 1 deletion x-pack/server/lib/check_license/check_license.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/

import { i18n } from '@kbn/i18n';
import { RANKED_LICENSE_TYPES } from '../constants';
import {
LICENSE_STATUS_UNAVAILABLE,
LICENSE_STATUS_INVALID,
LICENSE_STATUS_EXPIRED,
LICENSE_STATUS_VALID,
RANKED_LICENSE_TYPES,
} from '../../../common/constants';

export function checkLicense(pluginName, minimumLicenseRequired, xpackLicenseInfo) {
Expand Down
5 changes: 3 additions & 2 deletions x-pack/server/lib/check_license/check_license.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import {
LICENSE_STATUS_UNAVAILABLE,
LICENSE_STATUS_EXPIRED,
LICENSE_STATUS_VALID,
LICENSE_TYPE_BASIC,
} from '../../../common/constants';

describe('check_license', function () {

const pluginName = 'Foo';
const minimumLicenseRequired = 'basic';
const minimumLicenseRequired = LICENSE_TYPE_BASIC;
let mockLicenseInfo;
beforeEach(() => mockLicenseInfo = {});

Expand Down Expand Up @@ -46,7 +47,7 @@ describe('check_license', function () {
describe('license information is available', () => {
beforeEach(() => {
mockLicenseInfo.isAvailable = () => true;
set(mockLicenseInfo, 'license.getType', () => 'basic');
set(mockLicenseInfo, 'license.getType', () => LICENSE_TYPE_BASIC);
});

describe('& license is trial, standard, gold, platinum', () => {
Expand Down
8 changes: 0 additions & 8 deletions x-pack/server/lib/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,3 @@

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';

0 comments on commit 7afd091

Please sign in to comment.