Skip to content

Commit

Permalink
add enterprise license to x-pack plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Dec 5, 2019
1 parent ee469c9 commit 4815cf3
Show file tree
Hide file tree
Showing 36 changed files with 125 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
*/

export const REQUIRED_ROLES = ['beats_admin'];
export const REQUIRED_LICENSES = ['standard', 'gold', 'trial', 'platinum'];
export const LICENSES = ['oss', 'basic', 'standard', 'gold', 'trial', 'platinum'];
export type LicenseType = 'oss' | 'basic' | 'trial' | 'standard' | 'basic' | 'gold' | 'platinum';
export const REQUIRED_LICENSES = ['standard', 'gold', 'trial', 'platinum', 'enterprise'];
export const LICENSES = ['oss', 'basic', 'standard', 'gold', 'trial', 'platinum', 'enterprise'];
export type LicenseType =
| 'oss'
| 'basic'
| 'trial'
| 'standard'
| 'gold'
| 'platinum'
| 'enterprise';
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const RuntimeFrameworkInfo = t.interface(
basic: null,
gold: null,
platinum: null,
enterprise: null,
}),
expired: t.boolean,
expiry_date_in_millis: t.number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function checkLicense(xpackLicenseInfo) {
};
}

const VALID_LICENSE_MODES = [ 'trial', 'platinum' ];
const VALID_LICENSE_MODES = [ 'trial', 'platinum', 'enterprise' ];

const isLicenseModeValid = xpackLicenseInfo.license.isOneOf(VALID_LICENSE_MODES);
const isLicenseActive = xpackLicenseInfo.license.isActive();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ describe('check_license: ', function () {
set(mockLicenseInfo, 'feature', sinon.stub().withArgs('graph').returns({ isEnabled: () => true }));
});

describe('& license is trial or platinum', () => {
describe('& license is >= platinum', () => {
beforeEach(() => {
set(mockLicenseInfo, 'license.isOneOf', sinon.stub().withArgs([ 'trial', 'platinum' ]).returns(true));
set(mockLicenseInfo, 'license.isOneOf', sinon.stub().withArgs([ 'trial', 'platinum', 'enterprise' ]).returns(true));
set(mockLicenseInfo, 'license.getType', () => 'trial');
});

Expand Down Expand Up @@ -104,7 +104,7 @@ describe('check_license: ', function () {

});

describe('& license is neither trial nor platinum', () => {
describe('& license is < platinum', () => {
beforeEach(() => {
set(mockLicenseInfo, 'license.isOneOf', () => false);
set(mockLicenseInfo, 'license.getType', () => 'basic');
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/graph/server/lib/check_license.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function checkLicense(xpackLicenseInfo) {
});
}

if (xpackLicenseInfo.license.isOneOf([ 'trial', 'platinum' ])) {
if (xpackLicenseInfo.license.isOneOf([ 'trial', 'platinum', 'enterprise' ])) {
return {
showAppLink: true,
enableAppLink: isLicenseActive,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('check_license', function () {
set(mockLicenseInfo, 'license.getType', () => 'basic');
});

describe('& license is trial, standard, gold, platinum', () => {
describe('& license is > basic', () => {
beforeEach(() => set(mockLicenseInfo, 'license.isOneOf', () => true));

describe('& license is active', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ export function checkLicense(xpackLicenseInfo) {
}

const VALID_LICENSE_MODES = [
'trial',
'basic',
'standard',
'gold',
'platinum'
'platinum',
'enterprise',
'trial',
];

const isLicenseModeValid = xpackLicenseInfo.license.isOneOf(VALID_LICENSE_MODES);
Expand Down

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ describe('RequestTrialExtension component', () => {
expect(html).not.toBeNull();
expect(html).toMatchSnapshot();
});
test('should display when enterprise license is not active and trial has been used', () => {
const rendered = getComponent(
{
trialStatus: {
canStartTrial: false
},
license: createMockLicense('enterprise', 0)
},
RequestTrialExtension
);
const html = rendered.html();
expect(html).not.toBeNull();
expect(html).toMatchSnapshot();
});
test('should not display when platinum license is active and trial has been used', () => {
const rendered = getComponent(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ describe('StartTrial component when trial is allowed', () => {
);
expect(rendered.html()).toMatchSnapshot();
});
test('should not display for active enterprise license', () => {
const rendered = getComponent(
{
license: createMockLicense('enterprise'),
trialStatus: { canStartTrial: true }
},
StartTrial
);
expect(rendered.isEmptyRender()).toBeTruthy();
});
test('should display for expired enterprise license', () => {
const rendered = getComponent(
{
license: createMockLicense('enterprise', 0),
trialStatus: { canStartTrial: true }
},
StartTrial
);
expect(rendered.html()).toMatchSnapshot();
});
});

describe('StartTrial component when trial is not available', () => {
Expand Down Expand Up @@ -93,6 +113,16 @@ describe('StartTrial component when trial is not available', () => {
);
expect(rendered.isEmptyRender()).toBeTruthy();
});
test('should not display for enterprise license', () => {
const rendered = getComponent(
{
license: createMockLicense('enterprise'),
trialStatus: { canStartTrial: false }
},
StartTrial
);
expect(rendered.isEmptyRender()).toBeTruthy();
});

test('should not display for trial license', () => {
const rendered = getComponent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ export const shouldShowStartTrial = state => {
return (
state.trialStatus.canStartTrial &&
licenseType !== 'trial' &&
//don't show for platinum unless it is expired
(licenseType !== 'platinum' || isExpired(state))
//don't show for platinum & enterprise unless it is expired
((licenseType !== 'platinum' && licenseType !== 'enterprise') || isExpired(state))
);
};

Expand All @@ -121,7 +121,7 @@ export const shouldShowRequestTrialExtension = state => {
return false;
}
const { type } = getLicense(state);
return type !== 'platinum' || isExpired(state);
return (type !== 'platinum' && type !== 'enterprise') || isExpired(state);
};

export const startTrialError = state => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('check_license', function () {
set(mockLicenseInfo, 'license.getType', () => 'basic');
});

describe('& license is trial, standard, gold, platinum', () => {
describe('& license is > basic', () => {
beforeEach(() => {
set(mockLicenseInfo, 'license.isOneOf', () => true);
mockLicenseInfo.feature = () => ({ isEnabled: () => true }); // Security feature is enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export function checkLicense(xpackLicenseInfo) {
'trial',
'standard',
'gold',
'platinum'
'platinum',
'enterprise'
];

const isLicenseModeValid = xpackLicenseInfo.license.isOneOf(VALID_LICENSE_MODES);
Expand Down
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/maps/check_license.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function checkLicense(xPackInfo) {
'standard',
'gold',
'platinum',
'enterprise',
'trial',
]);

Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/ml/common/constants/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

export enum LICENSE_TYPE {
BASIC,
FULL, // platinum or trial
FULL, // >= platinum
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,28 @@
import expect from '@kbn/expect';
import sinon from 'sinon';
import { set } from 'lodash';
import { XPackInfo } from '../../../../../../../legacy/plugins/xpack_main/server/lib/xpack_info';
import { checkLicense } from '../check_license';
import { XPackInfo } from '../../../../xpack_main/server/lib/xpack_info';
import { checkLicense } from './check_license';

describe('check_license', () => {
let mockLicenseInfo: XPackInfo;
beforeEach(() => (mockLicenseInfo = {} as XPackInfo));

describe('license information is undefined', () => {
beforeEach(() => (mockLicenseInfo = {} as XPackInfo));

it('should set isAvailable to false', () => {
expect(checkLicense(mockLicenseInfo).isAvailable).to.be(false);
expect(checkLicense(undefined as any).isAvailable).to.be(false);
});

it('should set showLinks to true', () => {
expect(checkLicense(mockLicenseInfo).showLinks).to.be(true);
expect(checkLicense(undefined as any).showLinks).to.be(true);
});

it('should set enableLinks to false', () => {
expect(checkLicense(mockLicenseInfo).enableLinks).to.be(false);
expect(checkLicense(undefined as any).enableLinks).to.be(false);
});

it('should set a message', () => {
expect(checkLicense(mockLicenseInfo).message).to.not.be(undefined);
expect(checkLicense(undefined as any).message).to.not.be(undefined);
});
});

Expand Down Expand Up @@ -101,7 +99,7 @@ describe('check_license', () => {
);
});

describe('& license is trial or platinum', () => {
describe('& license is >= platinum', () => {
beforeEach(() => set(mockLicenseInfo, 'license.isOneOf', () => true));

describe('& license is active', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function checkLicense(xpackLicenseInfo: XPackInfo): Response {
};
}

const VALID_FULL_LICENSE_MODES = ['trial', 'platinum'];
const VALID_FULL_LICENSE_MODES = ['platinum', 'enterprise', 'trial'];

const isLicenseModeValid = xpackLicenseInfo.license.isOneOf(VALID_FULL_LICENSE_MODES);
const licenseType = isLicenseModeValid === true ? LICENSE_TYPE.FULL : LICENSE_TYPE.BASIC;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/monitoring/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const CALCULATE_DURATION_UNTIL = 'until';
/**
* In order to show ML Jobs tab in the Elasticsearch section / tab navigation, license must be supported
*/
export const ML_SUPPORTED_LICENSES = ['trial', 'platinum'];
export const ML_SUPPORTED_LICENSES = ['trial', 'platinum', 'enterprise'];

/**
* Metadata service URLs for the different cloud services that have constant URLs (e.g., unlike GCP, which is a constant prefix).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ describe('Monitoring Check License', () => {
});
});

it('enterprise active license - results true with no message', () => {
const result = checkLicense('enterprise', true, 'test-cluster-pqr');
expect(result).to.eql({
clusterAlerts: { enabled: true }
});
});

describe('Watcher is not enabled', () => {
it('platinum active license - watcher disabled - results false with message', () => {
const result = checkLicense('platinum', true, 'test-cluster-pqr', false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function checkLicense(type, active, clusterSource, watcher = true) {
}

// Disabled because the license type is not valid (basic)
if (!includes([ 'trial', 'standard', 'gold', 'platinum' ], type)) {
if (!includes([ 'trial', 'standard', 'gold', 'platinum', 'enterprise' ], type)) {
return Object.assign(licenseInfo, {
message: i18n.translate('xpack.monitoring.clusterAlerts.checkLicense.licenseIsBasicDescription', {
defaultMessage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export function register(registry: ExportTypesRegistry) {
jobContentExtension: 'csv',
createJobFactory,
executeJobFactory,
validLicenses: ['trial', 'basic', 'standard', 'gold', 'platinum'],
validLicenses: ['trial', 'basic', 'standard', 'gold', 'platinum', 'enterprise'],
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export function register(registry: ExportTypesRegistry) {
jobContentExtension: 'csv',
createJobFactory,
executeJobFactory,
validLicenses: ['trial', 'basic', 'standard', 'gold', 'platinum'],
validLicenses: ['trial', 'basic', 'standard', 'gold', 'platinum', 'enterprise'],
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export function register(registry: ExportTypesRegistry) {
jobContentExtension: 'PNG',
createJobFactory,
executeJobFactory,
validLicenses: ['trial', 'standard', 'gold', 'platinum'],
validLicenses: ['trial', 'standard', 'gold', 'platinum', 'enterprise'],
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export function register(registry: ExportTypesRegistry) {
jobContentExtension: 'pdf',
createJobFactory,
executeJobFactory,
validLicenses: ['trial', 'standard', 'gold', 'platinum'],
validLicenses: ['trial', 'standard', 'gold', 'platinum', 'enterprise'],
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('check_license', function () {
set(mockLicenseInfo, 'license.getType', () => 'basic');
});

describe('& license is trial, standard, gold, platinum', () => {
describe('& license is > basic', () => {
beforeEach(() => set(mockLicenseInfo, 'license.isOneOf', () => true));

describe('& license is active', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('check_license', function () {
set(mockLicenseInfo, 'license.getType', () => 'basic');
});

describe('& license is trial, standard, gold, platinum', () => {
describe('& license is > basic', () => {
beforeEach(() => set(mockLicenseInfo, 'license.isOneOf', () => true));

describe('& license is active', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export function checkLicense(xpackLicenseInfo) {
'basic',
'standard',
'gold',
'platinum'
'platinum',
'enterprise'
];

const isLicenseModeValid = xpackLicenseInfo.license.isOneOf(VALID_LICENSE_MODES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('check_license', () => {
set(mockLicenseInfo, 'license.getType', () => 'basic');
});

describe('& license is trial, standard, gold, platinum', () => {
describe('& license is > basic', () => {
beforeEach(() => set(mockLicenseInfo, 'license.isOneOf', () => true));

describe('& license is active', () => {
Expand Down
Loading

0 comments on commit 4815cf3

Please sign in to comment.