Skip to content

Commit

Permalink
Add basic wildcard search capabilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkambic committed Apr 10, 2020
1 parent fe01cf7 commit 2a8b2ba
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
40 changes: 39 additions & 1 deletion x-pack/plugins/uptime/server/lib/requests/get_certs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ import {

export interface GetCertsParams {
from: number;
search: string;
size: number;
}

export const getCerts: UMElasticsearchQueryFn<GetCertsParams, Cert[]> = async ({
callES,
dynamicSettings,
from,
search,
size,
}) => {
const params = {
const params: any = {
index: dynamicSettings.heartbeatIndices,
body: {
from,
Expand All @@ -47,6 +49,8 @@ export const getCerts: UMElasticsearchQueryFn<GetCertsParams, Cert[]> = async ({
},
},
_source: [
'monitor.id',
'monitor.name',
'tls.common_name',
'tls.sha256',
'tls.issued_by',
Expand All @@ -68,6 +72,40 @@ export const getCerts: UMElasticsearchQueryFn<GetCertsParams, Cert[]> = 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)) {
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/uptime/server/rest_api/certs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}),
Expand All @@ -23,11 +24,11 @@ export const createGetCertsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) =
tags: ['access:uptime-read'],
},
handler: async ({ callES, dynamicSettings }, _context, request, response): Promise<any> => {
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 }),
},
});
},
Expand Down

0 comments on commit 2a8b2ba

Please sign in to comment.