Skip to content

Commit

Permalink
[ML] Fix check for watcher being enabled (#43025) (#43036)
Browse files Browse the repository at this point in the history
* [ML] Fix check for watcher being enabled

* adding comments

* typo

* fixing test
  • Loading branch information
jgowdyelastic committed Aug 9, 2019
1 parent 07c4f71 commit 4d0200d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@

import expect from '@kbn/expect';
import { xpackInfo } from '../../../../xpack_main/public/services/xpack_info';
import { LICENSE_STATUS_VALID } from '../../../../../common/constants/license_status';
import {
xpackFeatureAvailable,
} from '../check_license';

const initialInfo = {
features: {
watcher: {
isAvailable: true
status: LICENSE_STATUS_VALID
}
}
};

describe('ML - check license', () => {
describe('xpackFeatureProvider', () => {
describe('xpackFeatureAvailable', () => {
beforeEach(() => {
xpackInfo.setAll(initialInfo);
});
Expand Down
15 changes: 14 additions & 1 deletion x-pack/legacy/plugins/ml/public/license/check_license.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from 'react';
import { xpackInfo } from '../../../xpack_main/public/services/xpack_info';
import { banners, addAppRedirectMessageToUrl } from 'ui/notify';
import { LICENSE_TYPE } from '../../common/constants/license';
import { LICENSE_STATUS_VALID } from '../../../../common/constants/license_status';

import chrome from 'ui/chrome';
import { EuiCallOut } from '@elastic/eui';
Expand Down Expand Up @@ -119,5 +120,17 @@ export function isFullLicense() {
}

export function xpackFeatureAvailable(feature) {
return xpackInfo.get(`features.${feature}.isAvailable`, false);
// each plugin can register their own set of features.
// so we need specific checks for each one.
// this list can grow if we need to check other plugin's features.
switch (feature) {
case 'watcher':
// watcher only has a license status feature
// if watcher is disabled in kibana.yml, the feature is completely missing from xpackInfo
return xpackInfo.get(`features.${feature}.status`, false) === LICENSE_STATUS_VALID;
default:
// historically plugins have used `isAvailable` as a catch all for
// license and feature enabled checks
return xpackInfo.get(`features.${feature}.isAvailable`, false);
}
}

0 comments on commit 4d0200d

Please sign in to comment.