From 2a8b2ba572d1edb1a261582d5cd739cbcea82940 Mon Sep 17 00:00:00 2001 From: Justin Kambic Date: Fri, 10 Apr 2020 17:30:43 -0400 Subject: [PATCH] Add basic wildcard search capabilities. --- .../uptime/server/lib/requests/get_certs.ts | 40 ++++++++++++++++++- .../plugins/uptime/server/rest_api/certs.ts | 5 ++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/uptime/server/lib/requests/get_certs.ts b/x-pack/plugins/uptime/server/lib/requests/get_certs.ts index 918f7ded8c73e5a..d85a4ad83d2796b 100644 --- a/x-pack/plugins/uptime/server/lib/requests/get_certs.ts +++ b/x-pack/plugins/uptime/server/lib/requests/get_certs.ts @@ -14,6 +14,7 @@ import { export interface GetCertsParams { from: number; + search: string; size: number; } @@ -21,9 +22,10 @@ export const getCerts: UMElasticsearchQueryFn = async ({ callES, dynamicSettings, from, + search, size, }) => { - const params = { + const params: any = { index: dynamicSettings.heartbeatIndices, body: { from, @@ -47,6 +49,8 @@ export const getCerts: UMElasticsearchQueryFn = async ({ }, }, _source: [ + 'monitor.id', + 'monitor.name', 'tls.common_name', 'tls.sha256', 'tls.issued_by', @@ -68,6 +72,40 @@ export const getCerts: UMElasticsearchQueryFn = async ({ }, }, }; + + if (search) { + params.body.query.bool.should = [ + { + wildcard: { + 'tls.issued_by': { + value: search, + }, + }, + }, + { + wildcard: { + 'tls.common_name': { + value: search, + }, + }, + }, + { + wildcard: { + 'monitor.id': { + value: search, + }, + }, + }, + { + wildcard: { + 'monitor.name': { + value: search, + }, + }, + }, + ]; + } + const result = await callES('search', params); const decodedResult = CertElasticsearchResponse.decode(result); if (isRight(decodedResult)) { diff --git a/x-pack/plugins/uptime/server/rest_api/certs.ts b/x-pack/plugins/uptime/server/rest_api/certs.ts index 172635b9d016aee..4177fc5d6c57773 100644 --- a/x-pack/plugins/uptime/server/rest_api/certs.ts +++ b/x-pack/plugins/uptime/server/rest_api/certs.ts @@ -14,6 +14,7 @@ export const createGetCertsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) = path: API_URLS.CERTS, validate: { query: schema.object({ + search: schema.maybe(schema.string()), from: schema.number(), size: schema.number(), }), @@ -23,11 +24,11 @@ export const createGetCertsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) = tags: ['access:uptime-read'], }, handler: async ({ callES, dynamicSettings }, _context, request, response): Promise => { - const { from, size } = request.query; + const { from, search, size } = request.query; return response.ok({ body: { - certs: await libs.requests.getCerts({ callES, dynamicSettings, from, size }), + certs: await libs.requests.getCerts({ callES, dynamicSettings, from, search, size }), }, }); },