Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Uptime]Abstracted 'access:uptime-read' tag into a wrapper for uptime rest routes #62576

Merged
merged 3 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const createRouteWithAuth = (
const licenseCheckHandler: UMRouteHandler = async (customParams, context, request, response) => {
const { statusCode, message } = libs.license(context.licensing.license);
if (statusCode === 200) {
return await handler(customParams, context, request, response);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return handler(customParams, context, request, response);
}
switch (statusCode) {
case 400:
Expand Down
4 changes: 1 addition & 3 deletions x-pack/plugins/uptime/server/rest_api/dynamic_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export const createGetDynamicSettingsRoute: UMRestApiRouteFactory = (libs: UMSer
method: 'GET',
path: '/api/uptime/dynamic_settings',
validate: false,
options: {
tags: ['access:uptime-read'],
},
handler: async ({ dynamicSettings }, _context, _request, response): Promise<any> => {
return response.ok({
body: dynamicSettings,
Expand All @@ -35,6 +32,7 @@ export const createPostDynamicSettingsRoute: UMRestApiRouteFactory = (libs: UMSe
validate: {
body: schema.object({}, { unknowns: 'allow' }),
},
writeAccess: true,
options: {
tags: ['access:uptime-write'],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export const createGetIndexPatternRoute: UMRestApiRouteFactory = (libs: UMServer
method: 'GET',
path: API_URLS.INDEX_PATTERN,
validate: false,
options: {
tags: ['access:uptime-read'],
},
handler: async ({ callES, dynamicSettings }, _context, _request, response): Promise<any> => {
try {
return response.ok({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export const createGetIndexStatusRoute: UMRestApiRouteFactory = (libs: UMServerL
method: 'GET',
path: API_URLS.INDEX_STATUS,
validate: false,
options: {
tags: ['access:uptime-read'],
},
handler: async ({ callES, dynamicSettings }, _context, _request, response): Promise<any> => {
try {
return response.ok({
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/uptime/server/rest_api/monitors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

export { createGetMonitorDetailsRoute } from './monitors_details';
export { createGetMonitorLocationsRoute } from './monitor_locations';
export { createGetStatusBarRoute } from './status';
export { createGetStatusBarRoute } from './monitor_status';
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export const createGetMonitorLocationsRoute: UMRestApiRouteFactory = (libs: UMSe
dateEnd: schema.string(),
}),
},
options: {
tags: ['access:uptime-read'],
},
handler: async ({ callES, dynamicSettings }, _context, request, response): Promise<any> => {
const { monitorId, dateStart, dateEnd } = request.query;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ export const createGetStatusBarRoute: UMRestApiRouteFactory = (libs: UMServerLib
dateEnd: schema.string(),
}),
},
options: {
tags: ['access:uptime-read'],
},
handler: async ({ callES, dynamicSettings }, _context, request, response): Promise<any> => {
const { monitorId, dateStart, dateEnd } = request.query;
const result = await libs.requests.getLatestMonitor({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export const createGetMonitorDetailsRoute: UMRestApiRouteFactory = (libs: UMServ
dateEnd: schema.maybe(schema.string()),
}),
},
options: {
tags: ['access:uptime-read'],
},
handler: async ({ callES, dynamicSettings }, _context, request, response): Promise<any> => {
const { monitorId, dateStart, dateEnd } = request.query;
return response.ok({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ export const createGetMonitorDurationRoute: UMRestApiRouteFactory = (libs: UMSer
dateEnd: schema.string(),
}),
},
options: {
tags: ['access:uptime-read'],
},
handler: async ({ callES, dynamicSettings }, _context, request, response): Promise<any> => {
const { monitorId, dateStart, dateEnd } = request.query;
return response.ok({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ export const createGetOverviewFilters: UMRestApiRouteFactory = (libs: UMServerLi
tags: arrayOrStringType,
}),
},

options: {
tags: ['access:uptime-read'],
},
handler: async ({ callES, dynamicSettings }, _context, request, response) => {
const { dateRangeStart, dateRangeEnd, locations, schemes, search, ports, tags } = request.query;

Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/uptime/server/rest_api/pings/get_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ export const createGetAllRoute: UMRestApiRouteFactory = (libs: UMServerLibs) =>
status: schema.maybe(schema.string()),
}),
},
options: {
tags: ['access:uptime-read'],
},
handler: async ({ callES, dynamicSettings }, _context, request, response): Promise<any> => {
const { dateRangeStart, dateRangeEnd, location, monitorId, size, sort, status } = request.query;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ export const createGetPingHistogramRoute: UMRestApiRouteFactory = (libs: UMServe
filters: schema.maybe(schema.string()),
}),
},
options: {
tags: ['access:uptime-read'],
},
handler: async ({ callES, dynamicSettings }, _context, request, response): Promise<any> => {
const { dateStart, dateEnd, statusFilter, monitorId, filters } = request.query;

Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/uptime/server/rest_api/pings/get_pings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ export const createGetPingsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) =
status: schema.maybe(schema.string()),
}),
},
options: {
tags: ['access:uptime-read'],
},
handler: async ({ callES, dynamicSettings }, _context, request, response): Promise<any> => {
const { dateRangeStart, dateRangeEnd, location, monitorId, size, sort, status } = request.query;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { schema } from '@kbn/config-schema';
import { UMServerLibs } from '../../lib/lib';
import { UMRestApiRouteFactory } from '../types';
import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants/rest_api';
import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants';

export const createGetSnapshotCount: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'GET',
Expand All @@ -20,9 +20,6 @@ export const createGetSnapshotCount: UMRestApiRouteFactory = (libs: UMServerLibs
statusFilter: schema.maybe(schema.string()),
}),
},
options: {
tags: ['access:uptime-read'],
},
handler: async ({ callES, dynamicSettings }, _context, request, response): Promise<any> => {
const { dateRangeStart, dateRangeEnd, filters, statusFilter } = request.query;
const result = await libs.requests.getSnapshotCount({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,4 @@ export const createLogPageViewRoute: UMRestApiRouteFactory = () => ({
body: result,
});
},
options: {
tags: ['access:uptime-read'],
},
});
1 change: 1 addition & 0 deletions x-pack/plugins/uptime/server/rest_api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { UMServerLibs } from '../lib/lib';
*/
export interface UMServerRoute<T> {
method: string;
writeAccess?: boolean;
handler: T;
}

Expand Down
35 changes: 17 additions & 18 deletions x-pack/plugins/uptime/server/rest_api/uptime_route_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@
import { UMKibanaRouteWrapper } from './types';
import { savedObjectsAdapter } from '../lib/saved_objects';

export const uptimeRouteWrapper: UMKibanaRouteWrapper = uptimeRoute => {
return {
...uptimeRoute,
handler: async (context, request, response) => {
const { callAsCurrentUser: callES } = context.core.elasticsearch.dataClient;
const { client: savedObjectsClient } = context.core.savedObjects;
const dynamicSettings = await savedObjectsAdapter.getUptimeDynamicSettings(
savedObjectsClient
);
return await uptimeRoute.handler(
{ callES, savedObjectsClient, dynamicSettings },
context,
request,
response
);
},
};
};
export const uptimeRouteWrapper: UMKibanaRouteWrapper = uptimeRoute => ({
...uptimeRoute,
options: {
tags: ['access:uptime-read', ...(uptimeRoute?.writeAccess ? ['access:uptime-write'] : [])],
},
handler: async (context, request, response) => {
const { callAsCurrentUser: callES } = context.core.elasticsearch.dataClient;
const { client: savedObjectsClient } = context.core.savedObjects;
const dynamicSettings = await savedObjectsAdapter.getUptimeDynamicSettings(savedObjectsClient);
return uptimeRoute.handler(
{ callES, savedObjectsClient, dynamicSettings },
context,
request,
response
);
},
});