-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SECURITY SOLUTION] Get case ids from alert ids (#98702)
* wip to get caseIds with alertId * make work the API with the latest aggs from SO :) * review * change logic to re-do aggregation if we think that we are missing data * Integration tests Co-authored-by: Jonathan Buttner <[email protected]>
- Loading branch information
1 parent
669be33
commit 5de608c
Showing
12 changed files
with
360 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
x-pack/plugins/cases/server/routes/api/cases/alerts/get_cases.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
import Boom from '@hapi/boom'; | ||
|
||
import { RouteDeps } from '../../types'; | ||
import { wrapError } from '../../utils'; | ||
import { CASE_ALERTS_URL } from '../../../../../common/constants'; | ||
|
||
export function initGetCaseIdsByAlertIdApi({ caseService, router, logger }: RouteDeps) { | ||
router.get( | ||
{ | ||
path: CASE_ALERTS_URL, | ||
validate: { | ||
params: schema.object({ | ||
alert_id: schema.string(), | ||
}), | ||
}, | ||
}, | ||
async (context, request, response) => { | ||
try { | ||
const alertId = request.params.alert_id; | ||
if (alertId == null || alertId === '') { | ||
throw Boom.badRequest('The `alertId` is not valid'); | ||
} | ||
const client = context.core.savedObjects.client; | ||
const caseIds = await caseService.getCaseIdsByAlertId({ | ||
client, | ||
alertId, | ||
}); | ||
|
||
return response.ok({ | ||
body: caseIds, | ||
}); | ||
} catch (error) { | ||
logger.error( | ||
`Failed to retrieve case ids for this alert id: ${request.params.alert_id}: ${error}` | ||
); | ||
return response.customError(wrapError(error)); | ||
} | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.