Skip to content

Commit

Permalink
refactor and type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
semd committed Aug 13, 2021
1 parent 63e033c commit d5c29fa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ export class AlertsClient {
};
}

private getAlertStatusFieldUpdate(
source: ParsedTechnicalFields | undefined,
status: STATUS_VALUES
) {
return source?.[ALERT_WORKFLOW_STATUS] == null
? { signal: { status } }
: { [ALERT_WORKFLOW_STATUS]: status };
}

/**
* Accepts an array of ES documents and executes ensureAuthorized for the given operation
* @param items
Expand Down Expand Up @@ -313,10 +322,7 @@ export class AlertsClient {
}

const bulkUpdateRequest = mgetRes.body.docs.flatMap((item) => {
const fieldToUpdate =
item?._source?.[ALERT_WORKFLOW_STATUS] == null
? { signal: { status } }
: { [ALERT_WORKFLOW_STATUS]: status };
const fieldToUpdate = this.getAlertStatusFieldUpdate(item?._source, status);
return [
{
update: {
Expand Down Expand Up @@ -508,12 +514,10 @@ export class AlertsClient {
this.logger.error(errorMessage);
throw Boom.notFound(errorMessage);
}

const fieldToUpdate =
alert?.hits.hits[0]._source?.[ALERT_WORKFLOW_STATUS] == null
? { signal: { status } }
: { [ALERT_WORKFLOW_STATUS]: status };

const fieldToUpdate = this.getAlertStatusFieldUpdate(
alert?.hits.hits[0]._source,
status as STATUS_VALUES
);
const { body: response } = await this.esClient.update<ParsedTechnicalFields>({
...decodeVersion(_version),
id,
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/security_solution/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ export const DETECTION_ENGINE_SIGNALS_MIGRATION_URL = `${DETECTION_ENGINE_SIGNAL
export const DETECTION_ENGINE_SIGNALS_MIGRATION_STATUS_URL = `${DETECTION_ENGINE_SIGNALS_URL}/migration_status`;
export const DETECTION_ENGINE_SIGNALS_FINALIZE_MIGRATION_URL = `${DETECTION_ENGINE_SIGNALS_URL}/finalize_migration`;

export const RAC_ALERTS_BULK_UPDATE_URL = '/internal/rac/alerts/bulk_update';

/**
* Common naming convention for an unauthenticated user
*/
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/timelines/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export const DEFAULT_NUMBER_FORMAT = 'format:number:defaultPattern';
export const FILTER_OPEN: AlertStatus = 'open';
export const FILTER_CLOSED: AlertStatus = 'closed';
export const FILTER_IN_PROGRESS: AlertStatus = 'in-progress';

export const RAC_ALERTS_BULK_UPDATE_URL = '/internal/rac/alerts/bulk_update';
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { CoreStart } from '../../../../../src/core/public';

import { useKibana } from '../../../../../src/plugins/kibana_react/public';
import { AlertStatus } from '../../../timelines/common';

export const RAC_ALERTS_BULK_UPDATE_URL = '/internal/rac/alerts/bulk_update';
import { RAC_ALERTS_BULK_UPDATE_URL } from '../../common/constants';

/**
* Update alert status by query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import expect from '@kbn/expect';

import type { estypes } from '@elastic/elasticsearch';
import { Signal } from '../../../../plugins/security_solution/server/lib/detection_engine/signals/types';
import {
RAC_ALERTS_BULK_UPDATE_URL,
DETECTION_ENGINE_QUERY_SIGNALS_URL,
} from '../../../../plugins/security_solution/common/constants';
import { DETECTION_ENGINE_QUERY_SIGNALS_URL } from '../../../../plugins/security_solution/common/constants';
import { RAC_ALERTS_BULK_UPDATE_URL } from '../../../../plugins/timelines/common/constants';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import {
createSignalsIndex,
Expand All @@ -39,29 +37,19 @@ export default ({ getService }: FtrProviderContext) => {
.post(RAC_ALERTS_BULK_UPDATE_URL)
.set('kbn-xsrf', 'true')
.send({ ids: ['123'], status: 'open', index: '.siem-signals-default' });
// .expect(200);
// console.error('BODY', JSON.stringify(body, null, 2));

// remove any server generated items that are indeterministic
delete body.took;

expect(body).to.eql(getSignalStatusEmptyResponse());
});

it('should not give errors when querying and the signals index does exist and is empty', async () => {
await createSignalsIndex(supertest);
const { body } = await supertest
await supertest
.post(RAC_ALERTS_BULK_UPDATE_URL)
.set('kbn-xsrf', 'true')
.send({ ids: ['123'], status: 'open', index: '.siem-signals-default' })
.expect(200);

// remove any server generated items that are indeterministic
// delete body.took;

// expect(body).to.eql(getSignalStatusEmptyResponse());

// await deleteSignalsIndex(supertest);
});
});

Expand Down

0 comments on commit d5c29fa

Please sign in to comment.