Skip to content

Commit

Permalink
Fixed ci type check errors for alerting and actions properties for SI…
Browse files Browse the repository at this point in the history
…EM RouteHandlerContext (#59400)

* Fixed ci type check errors for alerting and actions optional properties on RouteHandlerContext

* Reverted git revert b83f814
  • Loading branch information
YulNaumenko authored Mar 5, 2020
1 parent d55524c commit 4883d4b
Show file tree
Hide file tree
Showing 54 changed files with 144 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('add_prepackaged_rules_route', () => {
});

test('returns 404 if alertClient is not available on the route', async () => {
context.alerting.getAlertsClient = jest.fn();
context.alerting!.getAlertsClient = jest.fn();
const request = addPrepackagedRulesRequest();
const response = await server.inject(request, context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const addPrepackedRulesRoute = (router: IRouter) => {
const siemResponse = buildSiemResponse(response);

try {
if (!context.alerting || !context.actions) {
return siemResponse.error({ statusCode: 404 });
}
const alertsClient = context.alerting.getAlertsClient();
const actionsClient = context.actions.getActionsClient();
const clusterClient = context.core.elasticsearch.dataClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('create_rules_bulk', () => {
});

test('returns 404 if alertClient is not available on the route', async () => {
context.alerting.getAlertsClient = jest.fn();
context.alerting!.getAlertsClient = jest.fn();
const response = await server.inject(getReadBulkRequest(), context);
expect(response.status).toEqual(404);
expect(response.body).toEqual({ message: 'Not Found', status_code: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ export const createRulesBulkRoute = (router: IRouter) => {
},
},
async (context, request, response) => {
const siemResponse = buildSiemResponse(response);
if (!context.alerting || !context.actions) {
return siemResponse.error({ statusCode: 404 });
}
const alertsClient = context.alerting.getAlertsClient();
const actionsClient = context.actions.getActionsClient();
const clusterClient = context.core.elasticsearch.dataClient;
const siemClient = context.siem.getSiemClient();
const siemResponse = buildSiemResponse(response);

if (!actionsClient || !alertsClient) {
return siemResponse.error({ statusCode: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('create_rules', () => {
});

test('returns 404 if alertClient is not available on the route', async () => {
context.alerting.getAlertsClient = jest.fn();
context.alerting!.getAlertsClient = jest.fn();
const response = await server.inject(getCreateRequest(), context);
expect(response.status).toEqual(404);
expect(response.body).toEqual({ message: 'Not Found', status_code: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export const createRulesRoute = (router: IRouter): void => {
const siemResponse = buildSiemResponse(response);

try {
if (!context.alerting || !context.actions) {
return siemResponse.error({ statusCode: 404 });
}
const alertsClient = context.alerting.getAlertsClient();
const actionsClient = context.actions.getActionsClient();
const clusterClient = context.core.elasticsearch.dataClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('delete_rules', () => {
});

test('returns 404 if alertClient is not available on the route', async () => {
context.alerting.getAlertsClient = jest.fn();
context.alerting!.getAlertsClient = jest.fn();
const response = await server.inject(getDeleteBulkRequest(), context);
expect(response.status).toEqual(404);
expect(response.body).toEqual({ message: 'Not Found', status_code: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ export const deleteRulesBulkRoute = (router: IRouter) => {
},
};
const handler: Handler = async (context, request, response) => {
const siemResponse = buildSiemResponse(response);

if (!context.alerting || !context.actions) {
return siemResponse.error({ statusCode: 404 });
}
const alertsClient = context.alerting.getAlertsClient();
const actionsClient = context.actions.getActionsClient();
const savedObjectsClient = context.core.savedObjects.client;
const siemResponse = buildSiemResponse(response);

if (!actionsClient || !alertsClient) {
return siemResponse.error({ statusCode: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('delete_rules', () => {
});

test('returns 404 if alertClient is not available on the route', async () => {
context.alerting.getAlertsClient = jest.fn();
context.alerting!.getAlertsClient = jest.fn();
const response = await server.inject(getDeleteRequest(), context);

expect(response.status).toEqual(404);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const deleteRulesRoute = (router: IRouter) => {

try {
const { id, rule_id: ruleId } = request.query;
if (!context.alerting || !context.actions) {
return siemResponse.error({ statusCode: 404 });
}

const alertsClient = context.alerting.getAlertsClient();
const actionsClient = context.actions.getActionsClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export const exportRulesRoute = (router: IRouter, config: LegacyServices['config
},
},
async (context, request, response) => {
const alertsClient = context.alerting.getAlertsClient();
const siemResponse = buildSiemResponse(response);
if (!context.alerting) {
return siemResponse.error({ statusCode: 404 });
}
const alertsClient = context.alerting.getAlertsClient();

if (!alertsClient) {
return siemResponse.error({ statusCode: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('find_rules', () => {
});

test('returns 404 if alertClient is not available on the route', async () => {
context.alerting.getAlertsClient = jest.fn();
context.alerting!.getAlertsClient = jest.fn();
const response = await server.inject(getFindRequest(), context);
expect(response.status).toEqual(404);
expect(response.body).toEqual({ message: 'Not Found', status_code: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export const findRulesRoute = (router: IRouter) => {

try {
const { query } = request;
if (!context.alerting) {
return siemResponse.error({ statusCode: 404 });
}
const alertsClient = context.alerting.getAlertsClient();
const savedObjectsClient = context.core.savedObjects.client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('find_statuses', () => {
});

test('returns 404 if alertClient is not available on the route', async () => {
context.alerting.getAlertsClient = jest.fn();
context.alerting!.getAlertsClient = jest.fn();
const response = await server.inject(ruleStatusRequest(), context);
expect(response.status).toEqual(404);
expect(response.body).toEqual({ message: 'Not Found', status_code: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ export const findRulesStatusesRoute = (router: IRouter) => {
},
async (context, request, response) => {
const { query } = request;
const siemResponse = buildSiemResponse(response);
if (!context.alerting) {
return siemResponse.error({ statusCode: 404 });
}
const alertsClient = context.alerting.getAlertsClient();
const savedObjectsClient = context.core.savedObjects.client;
const siemResponse = buildSiemResponse(response);

if (!alertsClient) {
return siemResponse.error({ statusCode: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('get_prepackaged_rule_status_route', () => {
});

test('returns 404 if alertClient is not available on the route', async () => {
context.alerting.getAlertsClient = jest.fn();
context.alerting!.getAlertsClient = jest.fn();
const response = await server.inject(getPrepackagedRulesStatusRequest(), context);
expect(response.status).toEqual(404);
expect(response.body).toEqual({ message: 'Not Found', status_code: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ export const getPrepackagedRulesStatusRoute = (router: IRouter) => {
},
},
async (context, request, response) => {
const alertsClient = context.alerting.getAlertsClient();
const siemResponse = buildSiemResponse(response);
if (!context.alerting) {
return siemResponse.error({ statusCode: 404 });
}
const alertsClient = context.alerting.getAlertsClient();

if (!alertsClient) {
return siemResponse.error({ statusCode: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ describe('import_rules_route', () => {
});

test('returns 404 if alertClient is not available on the route', async () => {
context.alerting.getAlertsClient = jest.fn();
context.alerting!.getAlertsClient = jest.fn();
const response = await server.inject(request, context);
expect(response.status).toEqual(404);
expect(response.body).toEqual({ message: 'Not Found', status_code: 404 });
});

test('returns 404 if actionsClient is not available on the route', async () => {
context.actions.getActionsClient = jest.fn();
context.actions!.getActionsClient = jest.fn();
const response = await server.inject(request, context);
expect(response.status).toEqual(404);
expect(response.body).toEqual({ message: 'Not Found', status_code: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ export const importRulesRoute = (router: IRouter, config: LegacyServices['config
},
},
async (context, request, response) => {
const siemResponse = buildSiemResponse(response);

if (!context.alerting || !context.actions) {
return siemResponse.error({ statusCode: 404 });
}
const alertsClient = context.alerting.getAlertsClient();
const actionsClient = context.actions.getActionsClient();
const clusterClient = context.core.elasticsearch.dataClient;
const savedObjectsClient = context.core.savedObjects.client;
const siemClient = context.siem.getSiemClient();
const siemResponse = buildSiemResponse(response);

if (!actionsClient || !alertsClient) {
return siemResponse.error({ statusCode: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('patch_rules_bulk', () => {
});

test('returns 404 if alertClient is not available on the route', async () => {
context.alerting.getAlertsClient = jest.fn();
context.alerting!.getAlertsClient = jest.fn();
const response = await server.inject(getPatchBulkRequest(), context);
expect(response.status).toEqual(404);
expect(response.body).toEqual({ message: 'Not Found', status_code: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ export const patchRulesBulkRoute = (router: IRouter) => {
},
},
async (context, request, response) => {
const siemResponse = buildSiemResponse(response);

if (!context.alerting || !context.actions) {
return siemResponse.error({ statusCode: 404 });
}
const alertsClient = context.alerting.getAlertsClient();
const actionsClient = context.actions.getActionsClient();
const savedObjectsClient = context.core.savedObjects.client;
const siemResponse = buildSiemResponse(response);

if (!actionsClient || !alertsClient) {
return siemResponse.error({ statusCode: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('patch_rules', () => {
});

test('returns 404 if alertClient is not available on the route', async () => {
context.alerting.getAlertsClient = jest.fn();
context.alerting!.getAlertsClient = jest.fn();
const response = await server.inject(getPatchRequest(), context);
expect(response.status).toEqual(404);
expect(response.body).toEqual({ message: 'Not Found', status_code: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export const patchRulesRoute = (router: IRouter) => {
const siemResponse = buildSiemResponse(response);

try {
if (!context.alerting || !context.actions) {
return siemResponse.error({ statusCode: 404 });
}

const alertsClient = context.alerting.getAlertsClient();
const actionsClient = context.actions.getActionsClient();
const savedObjectsClient = context.core.savedObjects.client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('read_signals', () => {
});

test('returns 404 if alertClient is not available on the route', async () => {
context.alerting.getAlertsClient = jest.fn();
context.alerting!.getAlertsClient = jest.fn();
const response = await server.inject(getReadRequest(), context);
expect(response.status).toEqual(404);
expect(response.body).toEqual({ message: 'Not Found', status_code: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ export const readRulesRoute = (router: IRouter) => {
},
async (context, request, response) => {
const { id, rule_id: ruleId } = request.query;
const siemResponse = buildSiemResponse(response);

if (!context.alerting) {
return siemResponse.error({ statusCode: 404 });
}
const alertsClient = context.alerting.getAlertsClient();
const savedObjectsClient = context.core.savedObjects.client;
const siemResponse = buildSiemResponse(response);

try {
if (!alertsClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('update_rules_bulk', () => {
});

test('returns 404 if alertClient is not available on the route', async () => {
context.alerting.getAlertsClient = jest.fn();
context.alerting!.getAlertsClient = jest.fn();
const response = await server.inject(getUpdateBulkRequest(), context);
expect(response.status).toEqual(404);
expect(response.body).toEqual({ message: 'Not Found', status_code: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ export const updateRulesBulkRoute = (router: IRouter) => {
},
},
async (context, request, response) => {
const siemResponse = buildSiemResponse(response);

if (!context.alerting || !context.actions) {
return siemResponse.error({ statusCode: 404 });
}
const alertsClient = context.alerting.getAlertsClient();
const actionsClient = context.actions.getActionsClient();
const savedObjectsClient = context.core.savedObjects.client;
const siemClient = context.siem.getSiemClient();
const siemResponse = buildSiemResponse(response);

if (!actionsClient || !alertsClient) {
return siemResponse.error({ statusCode: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('update_rules', () => {
});

test('returns 404 if alertClient is not available on the route', async () => {
context.alerting.getAlertsClient = jest.fn();
context.alerting!.getAlertsClient = jest.fn();
const response = await server.inject(getUpdateRequest(), context);

expect(response.status).toEqual(404);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export const updateRulesRoute = (router: IRouter) => {
const siemResponse = buildSiemResponse(response);

try {
if (!context.alerting || !context.actions) {
return siemResponse.error({ statusCode: 404 });
}
const alertsClient = context.alerting.getAlertsClient();
const actionsClient = context.actions.getActionsClient();
const savedObjectsClient = context.core.savedObjects.client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ export const readTagsRoute = (router: IRouter) => {
},
},
async (context, request, response) => {
const alertsClient = context.alerting.getAlertsClient();
const siemResponse = buildSiemResponse(response);

if (!context.alerting) {
return siemResponse.error({ statusCode: 404 });
}
const alertsClient = context.alerting.getAlertsClient();

if (!alertsClient) {
return siemResponse.error({ statusCode: 404 });
}
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/actions/server/routes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export const createActionRoute = (router: IRouter, licenseState: LicenseState) =
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);

if (!context.actions) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for actions' });
}
const actionsClient = context.actions.getActionsClient();
const action = req.body;
const actionRes: ActionResult = await actionsClient.create({ action });
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/actions/server/routes/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export const deleteActionRoute = (router: IRouter, licenseState: LicenseState) =
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.actions) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for actions' });
}
const actionsClient = context.actions.getActionsClient();
const { id } = req.params;
await actionsClient.delete({ id });
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/actions/server/routes/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export const findActionRoute = (router: IRouter, licenseState: LicenseState) =>
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.actions) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for actions' });
}
const actionsClient = context.actions.getActionsClient();
const query = req.query;
const options: FindOptions['options'] = {
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/actions/server/routes/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export const getActionRoute = (router: IRouter, licenseState: LicenseState) => {
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.actions) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for actions' });
}
const actionsClient = context.actions.getActionsClient();
const { id } = req.params;
return res.ok({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('listActionTypesRoute', () => {
}
`);

expect(context.actions.listTypes).toHaveBeenCalledTimes(1);
expect(context.actions!.listTypes).toHaveBeenCalledTimes(1);

expect(res.ok).toHaveBeenCalledWith({
body: listTypes,
Expand Down
Loading

0 comments on commit 4883d4b

Please sign in to comment.