Skip to content

Commit

Permalink
dynamic settings work
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewvc committed Dec 20, 2019
1 parent a1bc3ff commit 0e5cf0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { UMRestApiRouteFactory } from '..';
import { schema } from '@kbn/config-schema';
import { UMServerLibs } from '../../lib/lib';
import { savedObjectsAdapter } from '../../lib/adapters';
import { UMDynamicSettingsType } from '../../lib/sources';
import { UMRestApiRouteFactory } from '..';

export const createGetDynamicSettingsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'GET',
Expand All @@ -24,16 +26,17 @@ export const createGetDynamicSettingsRoute: UMRestApiRouteFactory = (libs: UMSer
},
});

export const createSetDynamicSettingsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'PUT',
export const createPostDynamicSettingsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'POST',
path: '/api/uptime/dynamic_settings',
validate: false,
validate: schema.object({}, { allowUnknowns: true }),
options: {
tags: ['access:uptime'],
},
handler: async ({ savedObjectsClient }, _context, request, response): Promise<any> => {
console.log("BODY IS", request.body);
await savedObjectsAdapter.setUptimeSourceSettings(savedObjectsClient, JSON.parse(request.body));
// @ts-ignore
const newSettings: UMDynamicSettingsType = request.body;
await savedObjectsAdapter.setUptimeSourceSettings(savedObjectsClient, newSettings);

return response.ok({
body: {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/legacy/plugins/uptime/server/rest_api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { createGetAllRoute } from './pings';
import { createGetIndexPatternRoute } from './index_pattern';
import { createGetDynamicSettingsRoute } from './dynamic_settings';
import { createGetDynamicSettingsRoute, createPostDynamicSettingsRoute } from './dynamic_settings';
import { createLogMonitorPageRoute, createLogOverviewPageRoute } from './telemetry';
import { createGetSnapshotCount } from './snapshot';
import { UMRestApiRouteFactory } from './types';
Expand All @@ -19,6 +19,7 @@ export const restApiRoutes: UMRestApiRouteFactory[] = [
createGetAllRoute,
createGetIndexPatternRoute,
createGetDynamicSettingsRoute,
createPostDynamicSettingsRoute,
createGetMonitorDetailsRoute,
createGetMonitorLocationsRoute,
createGetSnapshotCount,
Expand Down

0 comments on commit 0e5cf0a

Please sign in to comment.