Skip to content

Commit

Permalink
Revert "Makes alerting and actions optional properties for interface …
Browse files Browse the repository at this point in the history
…RequestH… (#59264)"

This reverts commit 755439d.
  • Loading branch information
spalger committed Mar 5, 2020
1 parent bb86bf2 commit b83f814
Show file tree
Hide file tree
Showing 24 changed files with 4 additions and 64 deletions.
3 changes: 0 additions & 3 deletions x-pack/plugins/actions/server/routes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ 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: 0 additions & 3 deletions x-pack/plugins/actions/server/routes/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ 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: 0 additions & 3 deletions x-pack/plugins/actions/server/routes/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ 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: 0 additions & 3 deletions x-pack/plugins/actions/server/routes/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ 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
3 changes: 0 additions & 3 deletions x-pack/plugins/actions/server/routes/list_action_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ export const listActionTypesRoute = (router: IRouter, licenseState: LicenseState
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.actions) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for actions' });
}
return res.ok({
body: context.actions.listTypes(),
});
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/actions/server/routes/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ export const updateActionRoute = (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;
const { name, config, secrets } = req.body;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/actions/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface Services {

declare module 'src/core/server' {
interface RequestHandlerContext {
actions?: {
actions: {
getActionsClient: () => ActionsClient;
listTypes: ActionTypeRegistry['list'];
};
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/alerting/server/routes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ export const createAlertRoute = (router: IRouter, licenseState: LicenseState) =>
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);

if (!context.alerting) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
}
const alertsClient = context.alerting.getAlertsClient();
const alert = req.body;
const alertRes: Alert = await alertsClient.create({ data: alert });
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/alerting/server/routes/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ export const deleteAlertRoute = (router: IRouter, licenseState: LicenseState) =>
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.alerting) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
}
const alertsClient = context.alerting.getAlertsClient();
const { id } = req.params;
await alertsClient.delete({ id });
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/alerting/server/routes/disable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ export const disableAlertRoute = (router: IRouter, licenseState: LicenseState) =
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.alerting) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
}
const alertsClient = context.alerting.getAlertsClient();
const { id } = req.params;
await alertsClient.disable({ id });
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/alerting/server/routes/enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ export const enableAlertRoute = (router: IRouter, licenseState: LicenseState) =>
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.alerting) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
}
const alertsClient = context.alerting.getAlertsClient();
const { id } = req.params;
await alertsClient.enable({ id });
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/alerting/server/routes/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ export const findAlertRoute = (router: IRouter, licenseState: LicenseState) => {
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.alerting) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
}
const alertsClient = context.alerting.getAlertsClient();
const query = req.query;
const options: FindOptions['options'] = {
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/alerting/server/routes/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ export const getAlertRoute = (router: IRouter, licenseState: LicenseState) => {
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.alerting) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
}
const alertsClient = context.alerting.getAlertsClient();
const { id } = req.params;
return res.ok({
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/alerting/server/routes/get_alert_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ export const getAlertStateRoute = (router: IRouter, licenseState: LicenseState)
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.alerting) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
}
const alertsClient = context.alerting.getAlertsClient();
const { id } = req.params;
const state = await alertsClient.getAlertState({ id });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('listAlertTypesRoute', () => {
}
`);

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

expect(res.ok).toHaveBeenCalledWith({
body: listTypes,
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/alerting/server/routes/list_alert_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ export const listAlertTypesRoute = (router: IRouter, licenseState: LicenseState)
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.alerting) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
}
return res.ok({
body: context.alerting.listTypes(),
});
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/alerting/server/routes/mute_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ export const muteAllAlertRoute = (router: IRouter, licenseState: LicenseState) =
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.alerting) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
}
const alertsClient = context.alerting.getAlertsClient();
const { id } = req.params;
await alertsClient.muteAll({ id });
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/alerting/server/routes/mute_instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export const muteAlertInstanceRoute = (router: IRouter, licenseState: LicenseSta
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.alerting) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
}
const alertsClient = context.alerting.getAlertsClient();
const { alertId, alertInstanceId } = req.params;
await alertsClient.muteInstance({ alertId, alertInstanceId });
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/alerting/server/routes/unmute_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ export const unmuteAllAlertRoute = (router: IRouter, licenseState: LicenseState)
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.alerting) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
}
const alertsClient = context.alerting.getAlertsClient();
const { id } = req.params;
await alertsClient.unmuteAll({ id });
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/alerting/server/routes/unmute_instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export const unmuteAlertInstanceRoute = (router: IRouter, licenseState: LicenseS
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.alerting) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
}
const alertsClient = context.alerting.getAlertsClient();
const { alertId, alertInstanceId } = req.params;
await alertsClient.unmuteInstance({ alertId, alertInstanceId });
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/alerting/server/routes/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ export const updateAlertRoute = (router: IRouter, licenseState: LicenseState) =>
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.alerting) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
}
const alertsClient = context.alerting.getAlertsClient();
const { id } = req.params;
const { name, actions, params, schedule, tags } = req.body;
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/alerting/server/routes/update_api_key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ export const updateApiKeyRoute = (router: IRouter, licenseState: LicenseState) =
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
if (!context.alerting) {
return res.badRequest({ body: 'RouteHandlerContext is not registered for alerting' });
}
const alertsClient = context.alerting.getAlertsClient();
const { id } = req.params;
await alertsClient.updateApiKey({ id });
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type SpaceIdToNamespaceFunction = (spaceId?: string) => string | undefine

declare module 'src/core/server' {
interface RequestHandlerContext {
alerting?: {
alerting: {
getAlertsClient: () => AlertsClient;
listTypes: AlertTypeRegistry['list'];
};
Expand Down

0 comments on commit b83f814

Please sign in to comment.