Skip to content

Commit

Permalink
[ML] NP Server: make security and spaces plugins optional (#59156) (#…
Browse files Browse the repository at this point in the history
…59434)

* make security and spaces plugins optional

* update spacesPlugin name. update current user check
  • Loading branch information
alvarezmelissa87 authored Mar 6, 2020
1 parent 982b2bf commit 88d4633
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion x-pack/plugins/ml/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
9 changes: 6 additions & 3 deletions x-pack/plugins/ml/server/routes/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function getAnnotationsFeatureUnavailableErrorMessage() {
*/
export function annotationRoutes(
{ router, mlLicense }: RouteInitialization,
securityPlugin: SecurityPluginSetup
securityPlugin?: SecurityPluginSetup
) {
/**
* @apiGroup Annotations
Expand Down Expand Up @@ -101,9 +101,12 @@ export function annotationRoutes(
}

const { indexAnnotation } = annotationServiceProvider(context);
const user = securityPlugin.authc.getCurrentUser(request) || {};

const 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,
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/ml/server/routes/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/ml/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ export interface LicenseCheckResult {

export interface SystemRouteDeps {
cloud: CloudSetup;
spacesPlugin: SpacesPluginSetup;
spaces?: SpacesPluginSetup;
}

export interface PluginsSetup {
cloud: CloudSetup;
features: FeaturesPluginSetup;
home: HomeServerPluginSetup;
licensing: LicensingPluginSetup;
security: SecurityPluginSetup;
spaces: SpacesPluginSetup;
security?: SecurityPluginSetup;
spaces?: SpacesPluginSetup;
usageCollection: UsageCollectionSetup;
}

Expand Down

0 comments on commit 88d4633

Please sign in to comment.