Cleanup feature registration (#80909)

This commit is contained in:
Larry Gregory 2020-10-20 12:53:43 -04:00 committed by GitHub
parent b7ffefb48c
commit bf0f8bbb42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 19 additions and 178 deletions

View file

@ -12,12 +12,6 @@ exports[`FeatureRegistry Kibana Features prevents features from being registered
exports[`FeatureRegistry Kibana Features prevents features from being registered with a management id of "contains_invalid()_chars" 1`] = `"child \\"management\\" fails because [child \\"kibana\\" fails because [\\"kibana\\" at position 0 fails because [\\"0\\" with value \\"contains_invalid()_chars\\" fails to match the required pattern: /^[a-zA-Z0-9:_-]+$/]]]"`;
exports[`FeatureRegistry Kibana Features prevents features from being registered with a navLinkId of "" 1`] = `"child \\"navLinkId\\" fails because [\\"navLinkId\\" is not allowed to be empty]"`;
exports[`FeatureRegistry Kibana Features prevents features from being registered with a navLinkId of "contains space" 1`] = `"child \\"navLinkId\\" fails because [\\"navLinkId\\" with value \\"contains space\\" fails to match the required pattern: /^[a-zA-Z0-9:_-]+$/]"`;
exports[`FeatureRegistry Kibana Features prevents features from being registered with a navLinkId of "contains_invalid()_chars" 1`] = `"child \\"navLinkId\\" fails because [\\"navLinkId\\" with value \\"contains_invalid()_chars\\" fails to match the required pattern: /^[a-zA-Z0-9:_-]+$/]"`;
exports[`FeatureRegistry Kibana Features prevents features from being registered with an ID of "catalogue" 1`] = `"child \\"id\\" fails because [\\"id\\" contains an invalid value]"`;
exports[`FeatureRegistry Kibana Features prevents features from being registered with an ID of "doesn't match valid regex" 1`] = `"child \\"id\\" fails because [\\"id\\" with value \\"doesn't match valid regex\\" fails to match the required pattern: /^[a-zA-Z0-9_-]+$/]"`;

View file

@ -33,11 +33,9 @@ describe('FeatureRegistry', () => {
id: 'test-feature',
name: 'Test Feature',
excludeFromBasePrivileges: true,
icon: 'addDataApp',
navLinkId: 'someNavLink',
app: ['app1'],
category: { id: 'foo', label: 'foo' },
validLicenses: ['standard', 'basic', 'gold', 'platinum'],
minimumLicense: 'platinum',
catalogue: ['foo'],
management: {
foo: ['bar'],
@ -421,20 +419,6 @@ describe('FeatureRegistry', () => {
});
['contains space', 'contains_invalid()_chars', ''].forEach((prohibitedChars) => {
it(`prevents features from being registered with a navLinkId of "${prohibitedChars}"`, () => {
const featureRegistry = new FeatureRegistry();
expect(() =>
featureRegistry.registerKibanaFeature({
id: 'foo',
name: 'some feature',
navLinkId: prohibitedChars,
app: [],
category: { id: 'foo', label: 'foo' },
privileges: null,
})
).toThrowErrorMatchingSnapshot();
});
it(`prevents features from being registered with a management id of "${prohibitedChars}"`, () => {
const featureRegistry = new FeatureRegistry();
expect(() =>

View file

@ -91,12 +91,14 @@ const kibanaFeatureSchema = Joi.object({
category: appCategorySchema,
order: Joi.number(),
excludeFromBasePrivileges: Joi.boolean(),
validLicenses: Joi.array().items(
Joi.string().valid('basic', 'standard', 'gold', 'platinum', 'enterprise', 'trial')
minimumLicense: Joi.string().valid(
'basic',
'standard',
'gold',
'platinum',
'enterprise',
'trial'
),
icon: Joi.string(),
description: Joi.string(),
navLinkId: Joi.string().regex(uiCapabilitiesRegex),
app: Joi.array().items(Joi.string()).required(),
management: managementSchema,
catalogue: catalogueSchema,

View file

@ -21,8 +21,6 @@ export const buildOSSFeatures = ({ savedObjectTypes, includeTimelion }: BuildOSS
}),
order: 100,
category: DEFAULT_APP_CATEGORIES.kibana,
icon: 'discoverApp',
navLinkId: 'discover',
app: ['discover', 'kibana'],
catalogue: ['discover'],
privileges: {
@ -82,8 +80,6 @@ export const buildOSSFeatures = ({ savedObjectTypes, includeTimelion }: BuildOSS
}),
order: 700,
category: DEFAULT_APP_CATEGORIES.kibana,
icon: 'visualizeApp',
navLinkId: 'visualize',
app: ['visualize', 'lens', 'kibana'],
catalogue: ['visualize'],
privileges: {
@ -143,8 +139,6 @@ export const buildOSSFeatures = ({ savedObjectTypes, includeTimelion }: BuildOSS
}),
order: 200,
category: DEFAULT_APP_CATEGORIES.kibana,
icon: 'dashboardApp',
navLinkId: 'dashboards',
app: ['dashboards', 'kibana'],
catalogue: ['dashboard'],
privileges: {
@ -222,8 +216,6 @@ export const buildOSSFeatures = ({ savedObjectTypes, includeTimelion }: BuildOSS
}),
order: 1300,
category: DEFAULT_APP_CATEGORIES.management,
icon: 'devToolsApp',
navLinkId: 'dev_tools',
app: ['dev_tools', 'kibana'],
catalogue: ['console', 'searchprofiler', 'grokdebugger'],
privileges: {
@ -260,7 +252,6 @@ export const buildOSSFeatures = ({ savedObjectTypes, includeTimelion }: BuildOSS
}),
order: 1500,
category: DEFAULT_APP_CATEGORIES.management,
icon: 'advancedSettingsApp',
app: ['kibana'],
catalogue: ['advanced_settings'],
management: {
@ -300,7 +291,6 @@ export const buildOSSFeatures = ({ savedObjectTypes, includeTimelion }: BuildOSS
}),
order: 1600,
category: DEFAULT_APP_CATEGORIES.management,
icon: 'indexPatternApp',
app: ['kibana'],
catalogue: ['indexPatterns'],
management: {
@ -340,7 +330,6 @@ export const buildOSSFeatures = ({ savedObjectTypes, includeTimelion }: BuildOSS
}),
order: 1700,
category: DEFAULT_APP_CATEGORIES.management,
icon: 'savedObjectsApp',
app: ['kibana'],
catalogue: ['saved_objects'],
management: {
@ -384,8 +373,6 @@ const timelionFeature: KibanaFeatureConfig = {
name: 'Timelion',
order: 350,
category: DEFAULT_APP_CATEGORIES.kibana,
icon: 'timelionApp',
navLinkId: 'timelion',
app: ['timelion', 'kibana'],
catalogue: ['timelion'],
privileges: {

View file

@ -55,7 +55,7 @@ describe('GET /api/features', () => {
name: 'Licensed Feature',
app: ['bar-app'],
category: { id: 'foo', label: 'foo' },
validLicenses: ['gold'],
minimumLicense: 'gold',
privileges: null,
});

View file

@ -33,10 +33,9 @@ export function defineRoutes({ router, featureRegistry }: RouteDefinitionParams)
.filter(
(feature) =>
request.query.ignoreValidLicenses ||
!feature.validLicenses ||
!feature.validLicenses.length ||
(context.licensing!.license.type &&
feature.validLicenses.includes(context.licensing!.license.type))
!feature.minimumLicense ||
(context.licensing!.license &&
context.licensing!.license.hasAtLeast(feature.minimumLicense))
)
.sort(
(f1, f2) =>

View file

@ -92,7 +92,6 @@ describe('populateUICapabilities', () => {
new KibanaFeature({
id: 'newFeature',
name: 'my new feature',
navLinkId: 'newFeatureNavLink',
app: ['bar-app'],
category: { id: 'foo', label: 'foo' },
privileges: {
@ -146,7 +145,6 @@ describe('populateUICapabilities', () => {
new KibanaFeature({
id: 'newFeature',
name: 'my new feature',
navLinkId: 'newFeatureNavLink',
app: ['bar-app'],
category: { id: 'foo', label: 'foo' },
catalogue: ['anotherFooEntry', 'anotherBarEntry'],
@ -216,7 +214,6 @@ describe('populateUICapabilities', () => {
new KibanaFeature({
id: 'newFeature',
name: 'my new feature',
navLinkId: 'newFeatureNavLink',
app: ['bar-app'],
category: { id: 'foo', label: 'foo' },
privileges: {
@ -247,7 +244,6 @@ describe('populateUICapabilities', () => {
new KibanaFeature({
id: 'newFeature',
name: 'my new feature',
navLinkId: 'newFeatureNavLink',
app: ['bar-app'],
category: { id: 'foo', label: 'foo' },
privileges: null,
@ -292,7 +288,6 @@ describe('populateUICapabilities', () => {
new KibanaFeature({
id: 'newFeature',
name: 'my new feature',
navLinkId: 'newFeatureNavLink',
app: ['bar-app'],
category: { id: 'foo', label: 'foo' },
privileges: {
@ -364,7 +359,6 @@ describe('populateUICapabilities', () => {
new KibanaFeature({
id: 'newFeature',
name: 'my new feature',
navLinkId: 'newFeatureNavLink',
app: ['bar-app'],
category: { id: 'foo', label: 'foo' },
privileges: {
@ -385,7 +379,6 @@ describe('populateUICapabilities', () => {
new KibanaFeature({
id: 'yetAnotherNewFeature',
name: 'yet another new feature',
navLinkId: 'yetAnotherNavLink',
app: ['bar-app'],
category: { id: 'foo', label: 'foo' },
privileges: {