Skip to content

Commit

Permalink
[ML] New Platform server shim: update system routes (#57835) (#58011)
Browse files Browse the repository at this point in the history
* [ML] NP system routes

* [ML] apidoc.json

* [ML] address PR comments

* [ML] fix apidoc methods, passing es_search endpoint payload

* [ML] add dummy body validation for es_search, fix ignoreSpaces query param

* [ML] _has_privileges validate body
  • Loading branch information
darnautov committed Feb 20, 2020
1 parent 30cc81f commit e31ce90
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { IScopedClusterClient } from 'kibana/server';
import { Privileges, getDefaultPrivileges } from '../../../common/types/privileges';
import { XPackMainPlugin } from '../../../../xpack_main/server/xpack_main';
import { callWithRequestType } from '../../../common/types/kibana';
import { isSecurityDisabled } from '../../lib/security_utils';
import { upgradeCheckProvider } from './upgrade';
import { checkLicense } from '../check_license';
Expand All @@ -24,12 +24,12 @@ interface Response {
}

export function privilegesProvider(
callWithRequest: callWithRequestType,
callAsCurrentUser: IScopedClusterClient['callAsCurrentUser'],
xpackMainPlugin: XPackMainPlugin,
isMlEnabledInSpace: () => Promise<boolean>,
ignoreSpaces: boolean = false
) {
const { isUpgradeInProgress } = upgradeCheckProvider(callWithRequest);
const { isUpgradeInProgress } = upgradeCheckProvider(callAsCurrentUser);
async function getPrivileges(): Promise<Response> {
// get the default privileges, forced to be false.
const privileges = getDefaultPrivileges();
Expand Down Expand Up @@ -74,7 +74,7 @@ export function privilegesProvider(
} else {
// security enabled
// load all ml privileges for this user.
const { cluster } = await callWithRequest('ml.privilegeCheck', { body: mlPrivileges });
const { cluster } = await callAsCurrentUser('ml.privilegeCheck', { body: mlPrivileges });
setGettingPrivileges(cluster, privileges);
if (upgradeInProgress === false) {
// if an upgrade is in progress, don't apply the "setting"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { IScopedClusterClient } from 'kibana/server';
import { mlLog } from '../../client/log';
import { callWithRequestType } from '../../../common/types/kibana';

export function upgradeCheckProvider(callWithRequest: callWithRequestType) {
export function upgradeCheckProvider(callAsCurrentUser: IScopedClusterClient['callAsCurrentUser']) {
async function isUpgradeInProgress(): Promise<boolean> {
let upgradeInProgress = false;
try {
const info = await callWithRequest('ml.info');
const info = await callAsCurrentUser('ml.info');
// if ml indices are currently being migrated, upgrade_mode will be set to true
// pass this back with the privileges to allow for the disabling of UI controls.
upgradeInProgress = info.upgrade_mode === true;
Expand Down
205 changes: 0 additions & 205 deletions x-pack/legacy/plugins/ml/server/routes/system.js

This file was deleted.

Loading

0 comments on commit e31ce90

Please sign in to comment.