Skip to content

Commit d55524c

Browse files
[ML] NP Server: make security and spaces plugins optional (#59156)
* make security and spaces plugins optional * update spacesPlugin name. update current user check
1 parent 4371b1c commit d55524c

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

x-pack/plugins/ml/kibana.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "0.0.1",
44
"kibanaVersion": "kibana",
55
"configPath": ["ml"],
6-
"requiredPlugins": ["cloud", "features", "home", "licensing", "security", "spaces", "usageCollection"],
6+
"requiredPlugins": ["cloud", "features", "home", "licensing", "usageCollection"],
7+
"optionalPlugins": ["security", "spaces"],
78
"server": true,
89
"ui": false
910
}

x-pack/plugins/ml/server/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class MlServerPlugin {
117117
resultsServiceRoutes(routeInit);
118118
jobValidationRoutes(routeInit, this.version);
119119
systemRoutes(routeInit, {
120-
spacesPlugin: plugins.spaces,
120+
spaces: plugins.spaces,
121121
cloud: plugins.cloud,
122122
});
123123
initMlServerLog({ log: this.log });

x-pack/plugins/ml/server/routes/annotations.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function getAnnotationsFeatureUnavailableErrorMessage() {
3636
*/
3737
export function annotationRoutes(
3838
{ router, mlLicense }: RouteInitialization,
39-
securityPlugin: SecurityPluginSetup
39+
securityPlugin?: SecurityPluginSetup
4040
) {
4141
/**
4242
* @apiGroup Annotations
@@ -101,9 +101,12 @@ export function annotationRoutes(
101101
}
102102

103103
const { indexAnnotation } = annotationServiceProvider(context);
104-
const user = securityPlugin.authc.getCurrentUser(request) || {};
104+
105+
const currentUser =
106+
securityPlugin !== undefined ? securityPlugin.authc.getCurrentUser(request) : {};
105107
// @ts-ignore username doesn't exist on {}
106-
const resp = await indexAnnotation(request.body, user.username || ANNOTATION_USER_UNKNOWN);
108+
const username = currentUser?.username ?? ANNOTATION_USER_UNKNOWN;
109+
const resp = await indexAnnotation(request.body, username);
107110

108111
return response.ok({
109112
body: resp,

x-pack/plugins/ml/server/routes/system.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { RouteInitialization, SystemRouteDeps } from '../types';
1919
*/
2020
export function systemRoutes(
2121
{ router, mlLicense }: RouteInitialization,
22-
{ spacesPlugin, cloud }: SystemRouteDeps
22+
{ spaces, cloud }: SystemRouteDeps
2323
) {
2424
async function getNodeCount(context: RequestHandlerContext) {
2525
const filterPath = 'nodes.*.attributes';
@@ -120,8 +120,8 @@ export function systemRoutes(
120120
const ignoreSpaces = request.query && request.query.ignoreSpaces === 'true';
121121
// if spaces is disabled force isMlEnabledInSpace to be true
122122
const { isMlEnabledInSpace } =
123-
spacesPlugin !== undefined
124-
? spacesUtilsProvider(spacesPlugin, (request as unknown) as Request)
123+
spaces !== undefined
124+
? spacesUtilsProvider(spaces, (request as unknown) as Request)
125125
: { isMlEnabledInSpace: async () => true };
126126

127127
const { getPrivileges } = privilegesProvider(

x-pack/plugins/ml/server/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ export interface LicenseCheckResult {
2525

2626
export interface SystemRouteDeps {
2727
cloud: CloudSetup;
28-
spacesPlugin: SpacesPluginSetup;
28+
spaces?: SpacesPluginSetup;
2929
}
3030

3131
export interface PluginsSetup {
3232
cloud: CloudSetup;
3333
features: FeaturesPluginSetup;
3434
home: HomeServerPluginSetup;
3535
licensing: LicensingPluginSetup;
36-
security: SecurityPluginSetup;
37-
spaces: SpacesPluginSetup;
36+
security?: SecurityPluginSetup;
37+
spaces?: SpacesPluginSetup;
3838
usageCollection: UsageCollectionSetup;
3939
}
4040

0 commit comments

Comments
 (0)