From d9d5f73ddc02bf2f4fd83c9c5b50247441579f33 Mon Sep 17 00:00:00 2001 From: Melissa Alvarez Date: Tue, 3 Mar 2020 10:40:27 -0500 Subject: [PATCH 1/2] make security and spaces plugins optional --- x-pack/plugins/ml/kibana.json | 3 ++- x-pack/plugins/ml/server/plugin.ts | 2 +- x-pack/plugins/ml/server/routes/annotations.ts | 7 +++++-- x-pack/plugins/ml/server/types.ts | 6 +++--- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/ml/kibana.json b/x-pack/plugins/ml/kibana.json index e944af6821c0b..3bdf859731438 100644 --- a/x-pack/plugins/ml/kibana.json +++ b/x-pack/plugins/ml/kibana.json @@ -3,7 +3,8 @@ "version": "0.0.1", "kibanaVersion": "kibana", "configPath": ["ml"], - "requiredPlugins": ["cloud", "features", "home", "licensing", "security", "spaces", "usageCollection"], + "requiredPlugins": ["cloud", "features", "home", "licensing", "usageCollection"], + "optionalPlugins": ["security", "spaces"], "server": true, "ui": false } diff --git a/x-pack/plugins/ml/server/plugin.ts b/x-pack/plugins/ml/server/plugin.ts index a3f5733738432..263c533988feb 100644 --- a/x-pack/plugins/ml/server/plugin.ts +++ b/x-pack/plugins/ml/server/plugin.ts @@ -100,7 +100,7 @@ export class MlServerPlugin { mlLicense: this.mlLicense, }; - annotationRoutes(routeInit, plugins.security); + annotationRoutes(routeInit, plugins?.security); calendars(routeInit); dataFeedRoutes(routeInit); dataFrameAnalyticsRoutes(routeInit); diff --git a/x-pack/plugins/ml/server/routes/annotations.ts b/x-pack/plugins/ml/server/routes/annotations.ts index 16483bf8b887e..08be263ba37ba 100644 --- a/x-pack/plugins/ml/server/routes/annotations.ts +++ b/x-pack/plugins/ml/server/routes/annotations.ts @@ -36,7 +36,7 @@ function getAnnotationsFeatureUnavailableErrorMessage() { */ export function annotationRoutes( { router, mlLicense }: RouteInitialization, - securityPlugin: SecurityPluginSetup + securityPlugin?: SecurityPluginSetup ) { /** * @apiGroup Annotations @@ -101,7 +101,10 @@ export function annotationRoutes( } const { indexAnnotation } = annotationServiceProvider(context); - const user = securityPlugin.authc.getCurrentUser(request) || {}; + + const currentUser = + securityPlugin !== undefined && securityPlugin.authc.getCurrentUser(request); + const user = currentUser ? currentUser : {}; // @ts-ignore username doesn't exist on {} const resp = await indexAnnotation(request.body, user.username || ANNOTATION_USER_UNKNOWN); diff --git a/x-pack/plugins/ml/server/types.ts b/x-pack/plugins/ml/server/types.ts index aeb4c505ec55e..441055663ff79 100644 --- a/x-pack/plugins/ml/server/types.ts +++ b/x-pack/plugins/ml/server/types.ts @@ -25,7 +25,7 @@ export interface LicenseCheckResult { export interface SystemRouteDeps { cloud: CloudSetup; - spacesPlugin: SpacesPluginSetup; + spacesPlugin?: SpacesPluginSetup; } export interface PluginsSetup { @@ -33,8 +33,8 @@ export interface PluginsSetup { features: FeaturesPluginSetup; home: HomeServerPluginSetup; licensing: LicensingPluginSetup; - security: SecurityPluginSetup; - spaces: SpacesPluginSetup; + security?: SecurityPluginSetup; + spaces?: SpacesPluginSetup; usageCollection: UsageCollectionSetup; } From 97597910afc65cf90654df0adc44d49049a5f732 Mon Sep 17 00:00:00 2001 From: Melissa Alvarez Date: Wed, 4 Mar 2020 10:38:14 -0500 Subject: [PATCH 2/2] update spacesPlugin name. update current user check --- x-pack/plugins/ml/server/plugin.ts | 4 ++-- x-pack/plugins/ml/server/routes/annotations.ts | 6 +++--- x-pack/plugins/ml/server/routes/system.ts | 6 +++--- x-pack/plugins/ml/server/types.ts | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/ml/server/plugin.ts b/x-pack/plugins/ml/server/plugin.ts index 263c533988feb..547d3f8ab06cb 100644 --- a/x-pack/plugins/ml/server/plugin.ts +++ b/x-pack/plugins/ml/server/plugin.ts @@ -100,7 +100,7 @@ export class MlServerPlugin { mlLicense: this.mlLicense, }; - annotationRoutes(routeInit, plugins?.security); + annotationRoutes(routeInit, plugins.security); calendars(routeInit); dataFeedRoutes(routeInit); dataFrameAnalyticsRoutes(routeInit); @@ -117,7 +117,7 @@ export class MlServerPlugin { resultsServiceRoutes(routeInit); jobValidationRoutes(routeInit, this.version); systemRoutes(routeInit, { - spacesPlugin: plugins.spaces, + spaces: plugins.spaces, cloud: plugins.cloud, }); initMlServerLog({ log: this.log }); diff --git a/x-pack/plugins/ml/server/routes/annotations.ts b/x-pack/plugins/ml/server/routes/annotations.ts index 08be263ba37ba..c481fb8698855 100644 --- a/x-pack/plugins/ml/server/routes/annotations.ts +++ b/x-pack/plugins/ml/server/routes/annotations.ts @@ -103,10 +103,10 @@ export function annotationRoutes( const { indexAnnotation } = annotationServiceProvider(context); const currentUser = - securityPlugin !== undefined && securityPlugin.authc.getCurrentUser(request); - const user = currentUser ? currentUser : {}; + securityPlugin !== undefined ? securityPlugin.authc.getCurrentUser(request) : {}; // @ts-ignore username doesn't exist on {} - const resp = await indexAnnotation(request.body, user.username || ANNOTATION_USER_UNKNOWN); + const username = currentUser?.username ?? ANNOTATION_USER_UNKNOWN; + const resp = await indexAnnotation(request.body, username); return response.ok({ body: resp, diff --git a/x-pack/plugins/ml/server/routes/system.ts b/x-pack/plugins/ml/server/routes/system.ts index a0d7d312c04d4..2a0a760e94f79 100644 --- a/x-pack/plugins/ml/server/routes/system.ts +++ b/x-pack/plugins/ml/server/routes/system.ts @@ -19,7 +19,7 @@ import { RouteInitialization, SystemRouteDeps } from '../types'; */ export function systemRoutes( { router, mlLicense }: RouteInitialization, - { spacesPlugin, cloud }: SystemRouteDeps + { spaces, cloud }: SystemRouteDeps ) { async function getNodeCount(context: RequestHandlerContext) { const filterPath = 'nodes.*.attributes'; @@ -120,8 +120,8 @@ export function systemRoutes( const ignoreSpaces = request.query && request.query.ignoreSpaces === 'true'; // if spaces is disabled force isMlEnabledInSpace to be true const { isMlEnabledInSpace } = - spacesPlugin !== undefined - ? spacesUtilsProvider(spacesPlugin, (request as unknown) as Request) + spaces !== undefined + ? spacesUtilsProvider(spaces, (request as unknown) as Request) : { isMlEnabledInSpace: async () => true }; const { getPrivileges } = privilegesProvider( diff --git a/x-pack/plugins/ml/server/types.ts b/x-pack/plugins/ml/server/types.ts index 441055663ff79..def8a1e5fa649 100644 --- a/x-pack/plugins/ml/server/types.ts +++ b/x-pack/plugins/ml/server/types.ts @@ -25,7 +25,7 @@ export interface LicenseCheckResult { export interface SystemRouteDeps { cloud: CloudSetup; - spacesPlugin?: SpacesPluginSetup; + spaces?: SpacesPluginSetup; } export interface PluginsSetup {