Skip to content

Commit

Permalink
abstract access headers
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Apr 6, 2020
1 parent 4ab89e9 commit 5824b0f
Show file tree
Hide file tree
Showing 16 changed files with 7 additions and 44 deletions.
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);
return handler(customParams, context, request, response);
}
switch (statusCode) {
case 400:
Expand Down
3 changes: 0 additions & 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 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'],
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import { savedObjectsAdapter } from '../lib/saved_objects';
export const uptimeRouteWrapper: UMKibanaRouteWrapper = uptimeRoute => {
return {
...uptimeRoute,
options: {
tags: ['access:uptime-read', ...(uptimeRoute.options?.tags ?? [])],
},
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(
return uptimeRoute.handler(
{ callES, savedObjectsClient, dynamicSettings },
context,
request,
Expand Down

0 comments on commit 5824b0f

Please sign in to comment.