From 7d87a9d4c3078592ff6c68e3aa1261932f134e4e Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Mon, 29 Jun 2020 14:28:59 +0100 Subject: [PATCH] tiny type clean up --- .../ml/server/lib/capabilities/check_capabilities.ts | 2 ++ x-pack/plugins/ml/server/lib/capabilities/index.ts | 6 +++++- .../plugins/ml/server/shared_services/shared_services.ts | 6 +++--- .../detection_engine/signals/signal_rule_alert_type.ts | 9 +++++---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/ml/server/lib/capabilities/check_capabilities.ts b/x-pack/plugins/ml/server/lib/capabilities/check_capabilities.ts index 196eb3ec3daae..9b877aea46e0b 100644 --- a/x-pack/plugins/ml/server/lib/capabilities/check_capabilities.ts +++ b/x-pack/plugins/ml/server/lib/capabilities/check_capabilities.ts @@ -50,6 +50,8 @@ function disableAdminPrivileges(capabilities: MlCapabilities) { capabilities.canDeleteAnnotation = false; } +export type HasMlCapabilities = (capabilities: MlCapabilitiesKey[]) => void; + export function hasMlCapabilitiesProvider(resolveMlCapabilities: ResolveMlCapabilities) { return (request: KibanaRequest) => { return async (capabilities: MlCapabilitiesKey[]) => { diff --git a/x-pack/plugins/ml/server/lib/capabilities/index.ts b/x-pack/plugins/ml/server/lib/capabilities/index.ts index 9b6ac2f2dbe61..4e4e3c31ff16e 100644 --- a/x-pack/plugins/ml/server/lib/capabilities/index.ts +++ b/x-pack/plugins/ml/server/lib/capabilities/index.ts @@ -4,5 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -export { capabilitiesProvider, hasMlCapabilitiesProvider } from './check_capabilities'; +export { + capabilitiesProvider, + hasMlCapabilitiesProvider, + HasMlCapabilities, +} from './check_capabilities'; export { setupCapabilitiesSwitcher } from './capabilities_switcher'; diff --git a/x-pack/plugins/ml/server/shared_services/shared_services.ts b/x-pack/plugins/ml/server/shared_services/shared_services.ts index c876352ffac43..3345111fad4ae 100644 --- a/x-pack/plugins/ml/server/shared_services/shared_services.ts +++ b/x-pack/plugins/ml/server/shared_services/shared_services.ts @@ -18,8 +18,8 @@ import { AnomalyDetectorsProvider, getAnomalyDetectorsProvider, } from './providers/anomaly_detectors'; -import { ResolveMlCapabilities, MlCapabilitiesKey } from '../../common/types/capabilities'; -import { hasMlCapabilitiesProvider } from '../lib/capabilities'; +import { ResolveMlCapabilities } from '../../common/types/capabilities'; +import { hasMlCapabilitiesProvider, HasMlCapabilities } from '../lib/capabilities'; export type SharedServices = JobServiceProvider & AnomalyDetectorsProvider & @@ -30,7 +30,7 @@ export type SharedServices = JobServiceProvider & export interface SharedServicesChecks { isFullLicense(): void; isMinimumLicense(): void; - getHasMlCapabilities(request: KibanaRequest): (capabilities: MlCapabilitiesKey[]) => void; + getHasMlCapabilities(request: KibanaRequest): HasMlCapabilities; } export function createSharedServices( diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts index 9bc803a44fad7..66d913c5f554f 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts @@ -163,10 +163,11 @@ export const signalRulesAlertType = ({ } const scopedMlCallCluster = services.getScopedCallCluster(ml.mlClient); + // Using fake KibanaRequest as it is needed to satisfy the ML Services API, but can be empty as it is + // currently unused by the jobsSummary function. const summaryJobs = await ( await ml.jobServiceProvider(scopedMlCallCluster, ({} as unknown) as KibanaRequest) - ) // TODO, this is now broken - .jobsSummary([machineLearningJobId]); + ).jobsSummary([machineLearningJobId]); const jobSummary = summaryJobs.find((job) => job.id === machineLearningJobId); if (jobSummary == null || !isJobStarted(jobSummary.jobState, jobSummary.datafeedState)) { @@ -184,9 +185,9 @@ export const signalRulesAlertType = ({ const anomalyResults = await findMlSignals({ ml, callCluster: scopedMlCallCluster, - // This is needed to satisfy the ML Services API, but can be empty as it is + // Using fake KibanaRequest as it is needed to satisfy the ML Services API, but can be empty as it is // currently unused by the mlAnomalySearch function. - request: ({} as unknown) as KibanaRequest, // TODO, this is now broken + request: ({} as unknown) as KibanaRequest, jobId: machineLearningJobId, anomalyThreshold, from,