-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
move oss features registration to KP #66524
Changes from all commits
0816ade
c9ebc3a
a8af99a
670d7b0
ee39ebd
863d488
b7a7035
64af9c9
ec102c2
6634d5a
0b45f68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* 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. | ||
*/ | ||
import { coreMock, savedObjectsServiceMock } from 'src/core/server/mocks'; | ||
|
||
import { Plugin } from './plugin'; | ||
const initContext = coreMock.createPluginInitializerContext(); | ||
const coreSetup = coreMock.createSetup(); | ||
const coreStart = coreMock.createStart(); | ||
const typeRegistry = savedObjectsServiceMock.createTypeRegistryMock(); | ||
typeRegistry.getAllTypes.mockReturnValue([ | ||
{ | ||
name: 'foo', | ||
hidden: false, | ||
mappings: { properties: {} }, | ||
namespaceType: 'single' as 'single', | ||
}, | ||
{ | ||
name: 'bar', | ||
hidden: true, | ||
mappings: { properties: {} }, | ||
namespaceType: 'agnostic' as 'agnostic', | ||
}, | ||
]); | ||
coreStart.savedObjects.getTypeRegistry.mockReturnValue(typeRegistry); | ||
|
||
describe('Features Plugin', () => { | ||
it('returns OSS + registered features', async () => { | ||
const plugin = new Plugin(initContext); | ||
const { registerFeature } = await plugin.setup(coreSetup, {}); | ||
registerFeature({ | ||
id: 'baz', | ||
name: 'baz', | ||
app: [], | ||
privileges: null, | ||
}); | ||
|
||
const { getFeatures } = await plugin.start(coreStart); | ||
|
||
expect(getFeatures().map(f => f.id)).toMatchInlineSnapshot(` | ||
Array [ | ||
"baz", | ||
"discover", | ||
"visualize", | ||
"dashboard", | ||
"dev_tools", | ||
"advancedSettings", | ||
"indexPatterns", | ||
"savedObjectsManagement", | ||
] | ||
`); | ||
}); | ||
|
||
it('returns OSS + registered features with timelion when available', async () => { | ||
const plugin = new Plugin(initContext); | ||
const { registerFeature } = await plugin.setup(coreSetup, { | ||
visTypeTimelion: { uiEnabled: true }, | ||
}); | ||
registerFeature({ | ||
id: 'baz', | ||
name: 'baz', | ||
app: [], | ||
privileges: null, | ||
}); | ||
|
||
const { getFeatures } = await plugin.start(coreStart); | ||
|
||
expect(getFeatures().map(f => f.id)).toMatchInlineSnapshot(` | ||
Array [ | ||
"baz", | ||
"discover", | ||
"visualize", | ||
"dashboard", | ||
"dev_tools", | ||
"advancedSettings", | ||
"indexPatterns", | ||
"savedObjectsManagement", | ||
"timelion", | ||
] | ||
`); | ||
}); | ||
|
||
it('registers not hidden saved objects types', async () => { | ||
const plugin = new Plugin(initContext); | ||
await plugin.setup(coreSetup, {}); | ||
const { getFeatures } = await plugin.start(coreStart); | ||
|
||
const soTypes = | ||
getFeatures().find(f => f.id === 'savedObjectsManagement')?.privileges?.all.savedObject.all || | ||
[]; | ||
|
||
expect(soTypes.includes('foo')).toBe(true); | ||
expect(soTypes.includes('bar')).toBe(false); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
|
||
import { schema } from '@kbn/config-schema'; | ||
import { IRouter } from '../../../../../src/core/server'; | ||
import { LegacyAPI } from '../plugin'; | ||
import { FeatureRegistry } from '../feature_registry'; | ||
|
||
/** | ||
|
@@ -15,10 +14,9 @@ import { FeatureRegistry } from '../feature_registry'; | |
export interface RouteDefinitionParams { | ||
router: IRouter; | ||
featureRegistry: FeatureRegistry; | ||
getLegacyAPI: () => LegacyAPI; | ||
} | ||
|
||
export function defineRoutes({ router, featureRegistry, getLegacyAPI }: RouteDefinitionParams) { | ||
export function defineRoutes({ router, featureRegistry }: RouteDefinitionParams) { | ||
router.get( | ||
{ | ||
path: '/api/features', | ||
|
@@ -37,7 +35,8 @@ export function defineRoutes({ router, featureRegistry, getLegacyAPI }: RouteDef | |
request.query.ignoreValidLicenses || | ||
!feature.validLicenses || | ||
!feature.validLicenses.length || | ||
getLegacyAPI().xpackInfo.license.isOneOf(feature.validLicenses) | ||
(context.licensing!.license.type && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you want the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want |
||
feature.validLicenses.includes(context.licensing!.license.type)) | ||
) | ||
.sort( | ||
(f1, f2) => | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pgayvallet I wrongly assumed that
getAllTypes
should return already filtered types, assavedObjects.type
did in LP. Do we consider it's a problem that a plugin can expose all types to a consumer?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we use the type registry in the repository we need to know all types, but I think consumers of this API should usually only operate on types that are visible so I think it would make sense to make that the default. If we have a use case where this should be exposed outside of core we could have an option like
includedHiddenTypes: true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I named it
getAllTypes
in an attempt to distinguish it from the legacytypes
, but it's probably not enough and jsdoc is lacking.kibana/src/legacy/server/saved_objects/saved_objects_mixin.js
Lines 81 to 82 in 358d139
It shouldn't be a problem for a plugin to access / expose all types to a consumer. AFAIK, hidden types were already consumed in legacy, but for different usages, via the
schema
property that contains both visible and hidden types. Also I think some consumers need to access all types, even if I can't remember exactly for which usages, probably security/spaces)However I agree that 1/ the jsdoc for
getAllTypes
should be more explicit, and 2/ the type registry should have agetVisibleTypes
method.I will create a issue for that improvement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created #66818