Skip to content

Commit

Permalink
adds savedObjectsClient to the add and upate prepackaged rules and im…
Browse files Browse the repository at this point in the history
…port rules route.
  • Loading branch information
dhurley14 committed Jan 17, 2020
1 parent dadefe7 commit 6fb3b35
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ export const createAddPrepackedRulesRoute = (server: ServerFacade): Hapi.ServerR
const actionsClient = isFunction(request.getActionsClient)
? request.getActionsClient()
: null;

if (!alertsClient || !actionsClient) {
const savedObjectsClient = isFunction(request.getSavedObjectsClient)
? request.getSavedObjectsClient()
: null;
if (!alertsClient || !actionsClient || !savedObjectsClient) {
return headers.response().code(404);
}

Expand All @@ -59,7 +61,13 @@ export const createAddPrepackedRulesRoute = (server: ServerFacade): Hapi.ServerR
}
}
await installPrepackagedRules(alertsClient, actionsClient, rulesToInstall, spaceIndex);
await updatePrepackagedRules(alertsClient, actionsClient, rulesToUpdate, spaceIndex);
await updatePrepackagedRules(
alertsClient,
actionsClient,
savedObjectsClient,
rulesToUpdate,
spaceIndex
);
return {
rules_installed: rulesToInstall.length,
rules_updated: rulesToUpdate.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ export const createImportRulesRoute = (server: ServerFacade): Hapi.ServerRoute =
const actionsClient = isFunction(request.getActionsClient)
? request.getActionsClient()
: null;

if (!alertsClient || !actionsClient) {
const savedObjectsClient = isFunction(request.getSavedObjectsClient)
? request.getSavedObjectsClient()
: null;
if (!alertsClient || !actionsClient || !savedObjectsClient) {
return headers.response().code(404);
}
const { filename } = request.payload.file.hapi;
Expand Down Expand Up @@ -161,6 +163,7 @@ export const createImportRulesRoute = (server: ServerFacade): Hapi.ServerRoute =
const updatedRule = await updateRules({
alertsClient,
actionsClient,
savedObjectsClient,
description,
enabled,
falsePositives,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ export interface FindRulesStatusesRequest extends Omit<RequestFacade, 'query'> {
export interface Clients {
alertsClient: AlertsClient;
actionsClient: ActionsClient;
savedObjectsClient?: SavedObjectsClientContract;
}

export type UpdateRuleParams = Partial<RuleAlertParams> & {
id: string | undefined | null;
savedObjectsClient: SavedObjectsClientContract;
} & Clients;

export type DeleteRuleParams = Clients & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SavedObjectsClientContract } from 'kibana/server';
import { ActionsClient } from '../../../../../actions';
import { AlertsClient } from '../../../../../alerting';
import { updateRules } from './update_rules';
Expand All @@ -12,6 +13,7 @@ import { RuleAlertParamsRest } from '../types';
export const updatePrepackagedRules = async (
alertsClient: AlertsClient,
actionsClient: ActionsClient,
savedObjectsClient: SavedObjectsClientContract,
rules: RuleAlertParamsRest[],
outputIndex: string
): Promise<void> => {
Expand Down Expand Up @@ -55,6 +57,7 @@ export const updatePrepackagedRules = async (
outputIndex,
id: undefined, // We never have an id when updating from pre-packaged rules
savedId,
savedObjectsClient,
meta,
filters,
ruleId,
Expand Down

0 comments on commit 6fb3b35

Please sign in to comment.