Skip to content
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

[ML] NP Server: make security and spaces plugins optional #59156

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this @ts-ignore can go now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That warning still shows up since currentUser can still be {} 😞

Copy link
Member

@jgowdyelastic jgowdyelastic Mar 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok. i missed that.
would it be worth changing the line above to make currentUser null or undefined in that situation?
As it would be caught by currentUser?.username ?? on the line below.

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