Skip to content

Commit

Permalink
passing sortOrder and size (#665)
Browse files Browse the repository at this point in the history
Signed-off-by: Amardeepsingh Siglani <[email protected]>
  • Loading branch information
amsiglan authored Jul 24, 2023
1 parent 91068ef commit 15f2e2f
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 10 deletions.
7 changes: 6 additions & 1 deletion public/services/AlertsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ export default class AlertsService {
detectorParams: GetAlertsParams
): Promise<ServerResponse<GetAlertsResponse>> => {
const { detectorType, detector_id } = detectorParams;
let query: GetAlertsParams | {} = {};
let query: GetAlertsParams | {} = {
sortOrder: 'desc',
size: 10000,
};

if (detector_id) {
query = {
...query,
detector_id,
};
} else if (detectorType) {
query = {
...query,
detectorType,
};
}
Expand Down
7 changes: 6 additions & 1 deletion public/services/FindingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ export default class FindingsService {
detectorParams: GetFindingsParams
): Promise<ServerResponse<GetFindingsResponse>> => {
const { detectorType, detectorId } = detectorParams;
let query: GetFindingsParams | {} = {};
let query: GetFindingsParams | {} = {
sortOrder: 'desc',
size: 10000,
};

if (detectorId) {
query = {
...query,
detectorId,
};
} else if (detectorType) {
query = {
...query,
detectorType,
};
}
Expand Down
10 changes: 9 additions & 1 deletion server/clusters/addAlertsMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ import { METHOD_NAMES, API, BASE_API_PATH } from '../utils/constants';
export function addAlertsMethods(securityAnalytics: any, createAction: any): void {
securityAnalytics[METHOD_NAMES.GET_ALERTS] = createAction({
url: {
fmt: `${API.GET_ALERTS}?detector_id=<%=detector_id%>`,
fmt: `${API.GET_ALERTS}?detector_id=<%=detector_id%>&sortOrder=<%=sortOrder%>&size=<%=size%>`,
req: {
detector_id: {
type: 'string',
required: false,
},
sortOrder: {
type: 'string',
required: false,
},
size: {
type: 'number',
required: false,
},
},
},
needBody: false,
Expand Down
10 changes: 9 additions & 1 deletion server/clusters/addFindingsMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ import { METHOD_NAMES, API } from '../utils/constants';
export function addFindingsMethods(securityAnalytics: any, createAction: any): void {
securityAnalytics[METHOD_NAMES.GET_FINDINGS] = createAction({
url: {
fmt: `${API.GET_FINDINGS}?detector_id=<%=detectorId%>`,
fmt: `${API.GET_FINDINGS}?detector_id=<%=detectorId%>&sortOrder=<%=sortOrder%>&size=<%=size%>`,
req: {
detectorId: {
type: 'string',
required: false,
},
sortOrder: {
type: 'string',
required: false,
},
size: {
type: 'number',
required: false,
},
},
},
needBody: false,
Expand Down
8 changes: 6 additions & 2 deletions server/models/interfaces/Alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
* SPDX-License-Identifier: Apache-2.0
*/

export type GetAlertsParams =
export type GetAlertsParams = {
sortOrder?: string;
size?: number;
} & (
| {
detector_id: string;
detectorType?: string;
}
| {
detectorType: string;
detector_id?: string;
};
}
);

export interface GetAlertsResponse {
alerts: AlertResponse[];
Expand Down
8 changes: 6 additions & 2 deletions server/models/interfaces/Findings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@

import { Finding } from '../../../public/pages/Findings/models/interfaces';

export type GetFindingsParams =
export type GetFindingsParams = {
sortOrder?: string;
size?: number;
} & (
| {
detectorId: string;
detectorType?: string;
}
| {
detectorType: string;
detectorId?: string;
};
}
);

export interface GetFindingsResponse {
total_findings: number;
Expand Down
2 changes: 2 additions & 0 deletions server/routes/AlertRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export function setupAlertsRoutes(services: NodeServices, router: IRouter) {
query: schema.object({
detectorType: schema.maybe(schema.string()),
detector_id: schema.maybe(schema.string()),
sortOrder: schema.maybe(schema.string()),
size: schema.maybe(schema.number()),
}),
},
},
Expand Down
2 changes: 2 additions & 0 deletions server/routes/FindingsRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export function setupFindingsRoutes(services: NodeServices, router: IRouter) {
query: schema.object({
detectorType: schema.maybe(schema.string()),
detectorId: schema.maybe(schema.string()),
sortOrder: schema.maybe(schema.string()),
size: schema.maybe(schema.number()),
}),
},
},
Expand Down
8 changes: 7 additions & 1 deletion server/services/AlertService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,21 @@ export default class AlertService {
response: OpenSearchDashboardsResponseFactory
): Promise<IOpenSearchDashboardsResponse<ServerResponse<GetAlertsResponse> | ResponseError>> => {
try {
const { detectorType, detector_id } = request.query;
const { detectorType, detector_id, sortOrder, size } = request.query;
const defaultParams = {
sortOrder,
size,
};
let params: GetAlertsParams;

if (detector_id) {
params = {
...defaultParams,
detector_id,
};
} else if (detectorType) {
params = {
...defaultParams,
detectorType,
};
} else {
Expand Down
8 changes: 7 additions & 1 deletion server/services/FindingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,21 @@ export default class FindingsService {
IOpenSearchDashboardsResponse<ServerResponse<GetFindingsResponse> | ResponseError>
> => {
try {
const { detectorType, detectorId } = request.query;
const { detectorType, detectorId, sortOrder, size } = request.query;
const defaultParams = {
sortOrder,
size,
};
let params: GetFindingsParams;

if (detectorId) {
params = {
...defaultParams,
detectorId,
};
} else if (detectorType) {
params = {
...defaultParams,
detectorType,
};
} else {
Expand Down

0 comments on commit 15f2e2f

Please sign in to comment.