forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds get route, working when tested locally
- Loading branch information
Showing
10 changed files
with
163 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export const BASE_RAC_ALERTS_API_PATH = '/api/rac/alerts'; |
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
42 changes: 42 additions & 0 deletions
42
x-pack/plugins/rule_registry/server/routes/get_alert_by_id.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,42 @@ | ||
/* | ||
* 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 { IRouter } from 'kibana/server'; | ||
import * as t from 'io-ts'; | ||
import { id as _id } from '@kbn/securitysolution-io-ts-list-types'; | ||
|
||
import { RacRequestHandlerContext } from '../types'; | ||
import { BASE_RAC_ALERTS_API_PATH } from '../../common/constants'; | ||
import { buildRouteValidation } from './utils/route_validation'; | ||
|
||
export const getAlertByIdRoute = (router: IRouter<RacRequestHandlerContext>) => { | ||
router.get( | ||
{ | ||
path: BASE_RAC_ALERTS_API_PATH, | ||
validate: { | ||
query: buildRouteValidation( | ||
t.exact( | ||
t.type({ | ||
id: _id, | ||
}) | ||
) | ||
), | ||
}, | ||
options: { | ||
tags: ['access:rac'], | ||
}, | ||
}, | ||
async (context, request, response) => { | ||
const alertsClient = await context.rac.getAlertsClient(); | ||
const { id } = request.query; | ||
const alert = await alertsClient.get({ id }); | ||
return response.ok({ | ||
body: alert, | ||
}); | ||
} | ||
); | ||
}; |
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,14 @@ | ||
/* | ||
* 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 { IRouter } from 'kibana/server'; | ||
import { RacRequestHandlerContext } from '../types'; | ||
import { getAlertByIdRoute } from './get_alert_by_id'; | ||
|
||
export function defineRoutes(router: IRouter<RacRequestHandlerContext>) { | ||
getAlertByIdRoute(router); | ||
} |
56 changes: 56 additions & 0 deletions
56
x-pack/plugins/rule_registry/server/routes/utils/route_validation.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,56 @@ | ||
/* | ||
* 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. | ||
*/ | ||
/* | ||
* 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 { fold } from 'fp-ts/lib/Either'; | ||
import { pipe } from 'fp-ts/lib/pipeable'; | ||
import * as rt from 'io-ts'; | ||
import { exactCheck, formatErrors } from '@kbn/securitysolution-io-ts-utils'; | ||
|
||
import { | ||
RouteValidationError, | ||
RouteValidationFunction, | ||
RouteValidationResultFactory, | ||
} from '../../../../../../src/core/server'; | ||
|
||
type RequestValidationResult<T> = | ||
| { | ||
value: T; | ||
error?: undefined; | ||
} | ||
| { | ||
value?: undefined; | ||
error: RouteValidationError; | ||
}; | ||
|
||
/** | ||
* Copied from x-pack/plugins/security_solution/server/utils/build_validation/route_validation.ts | ||
* This really should be in @kbn/securitysolution-io-ts-utils rather than copied yet again, however, this has types | ||
* from a lot of places such as RouteValidationResultFactory from core/server which in turn can pull in @kbn/schema | ||
* which cannot work on the front end and @kbn/securitysolution-io-ts-utils works on both front and backend. | ||
* | ||
* TODO: Figure out a way to move this function into a package rather than copying it/forking it within plugins | ||
*/ | ||
export const buildRouteValidation = <T extends rt.Mixed, A = rt.TypeOf<T>>( | ||
schema: T | ||
): RouteValidationFunction<A> => ( | ||
inputValue: unknown, | ||
validationResult: RouteValidationResultFactory | ||
): RequestValidationResult<A> => | ||
pipe( | ||
schema.decode(inputValue), | ||
(decoded) => exactCheck(inputValue, decoded), | ||
fold<rt.Errors, A, RequestValidationResult<A>>( | ||
(errors: rt.Errors) => validationResult.badRequest(formatErrors(errors).join()), | ||
(validatedInput: A) => validationResult.ok(validatedInput) | ||
) | ||
); |
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/rule_registry/server/scripts/get_alert_by_id.sh
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,15 @@ | ||
#!/bin/sh | ||
|
||
# | ||
# 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. | ||
# | ||
|
||
set -e | ||
|
||
# Example: ./get_alert_by_id.sh {id} | ||
curl -s -k \ | ||
-u ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD} \ | ||
-X GET ${KIBANA_URL}${SPACE_URL}/api/rac/alerts?id="$1" | jq . |
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