-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[ML] NP Server: make security and spaces plugins optional #59156
Conversation
Pinging @elastic/ml-ui (:ml) |
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.
Added a couple of comments but LGMT
x-pack/plugins/ml/server/plugin.ts
Outdated
@@ -103,7 +103,7 @@ export class MlServerPlugin { | |||
getLicenseCheckResults: () => this.licenseCheckResults, | |||
}; | |||
|
|||
annotationRoutes(routeInit, plugins.security); | |||
annotationRoutes(routeInit, plugins?.security); |
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.
plugins
won't be undefined here
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.
Good catch - fixed in 6fdc3375d75d9381b53e972c7a484d13b3dfc514
x-pack/plugins/ml/server/types.ts
Outdated
@@ -24,16 +24,16 @@ export interface LicenseCheckResult { | |||
|
|||
export interface SystemRouteDeps { | |||
cloud: CloudSetup; | |||
spacesPlugin: SpacesPluginSetup; | |||
spacesPlugin?: SpacesPluginSetup; |
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 just noticed that we use spacesPlugin
here and spaces
in PluginsSetup
to refer to SpacesPluginSetup
but we use cloud
in both to refer to CloudSetup
.
It would be nice to have consistent naming for all plugin dependencies.
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.
but i'm not suggesting we change it in this PR. it's a bit out of scope
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.
It was a small change as it's only used in one of the route files. Updated here: 6fdc3375d75d9381b53e972c7a484d13b3dfc514
|
||
const currentUser = | ||
securityPlugin !== undefined && securityPlugin.authc.getCurrentUser(request); | ||
const user = currentUser ? currentUser : {}; |
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.
looking at the User
type, username
isn't optional, so this check could probably be
const username = currentUser?.username || ANNOTATION_USER_UNKNOWN;
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.
Prefer the ??
operator, even if it does the same here.
const username = currentUser?.username ?? ANNOTATION_USER_UNKNOWN;
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.
Good point - updated 6fdc3375d75d9381b53e972c7a484d13b3dfc514
545409c
to
ca7f16e
Compare
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.
Added a comment to remove a comment, but otherwise
LGTM
@@ -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 {} |
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.
looks like this @ts-ignore
can go now
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.
That warning still shows up since currentUser
can still be {} 😞
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.
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.
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.
Tested and LGTM
retest |
6fdc337
to
77685dd
Compare
77685dd
to
9759791
Compare
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
Summary
Ensure ml plugin works with security disabled. Moves
security
andspaces
plugins from required to optional inkibana.json