|
4 | 4 | * you may not use this file except in compliance with the Elastic License. |
5 | 5 | */ |
6 | 6 |
|
7 | | -import { Legacy } from 'kibana'; |
| 7 | +import { schema } from '@kbn/config-schema'; |
8 | 8 | import querystring from 'querystring'; |
| 9 | +import { authorizedUserPreRoutingFactory } from './lib/authorized_user_pre_routing'; |
9 | 10 | import { API_BASE_URL } from '../../common/constants'; |
10 | | -import { ReportingSetupDeps, ServerFacade } from '../types'; |
11 | | -import { |
12 | | - getRouteConfigFactoryReportingPre, |
13 | | - GetRouteConfigFactoryFn, |
14 | | -} from './lib/route_config_factories'; |
15 | 11 | import { HandlerErrorFunction, HandlerFunction } from './types'; |
16 | 12 | import { ReportingCore } from '../core'; |
17 | 13 | import { LevelLogger } from '../lib'; |
18 | 14 |
|
19 | | -const getStaticFeatureConfig = (getRouteConfig: GetRouteConfigFactoryFn, featureId: string) => |
20 | | - getRouteConfig(() => featureId); |
21 | | - |
22 | 15 | const BASE_GENERATE = `${API_BASE_URL}/generate`; |
23 | 16 |
|
24 | 17 | export function registerLegacy( |
25 | 18 | reporting: ReportingCore, |
26 | | - server: ServerFacade, |
27 | | - plugins: ReportingSetupDeps, |
28 | 19 | handler: HandlerFunction, |
29 | 20 | handleError: HandlerErrorFunction, |
30 | 21 | logger: LevelLogger |
31 | 22 | ) { |
32 | | - const config = reporting.getConfig(); |
33 | | - const getRouteConfig = getRouteConfigFactoryReportingPre(config, plugins, logger); |
| 23 | + const { router } = reporting.getPluginSetupDeps(); |
| 24 | + const userHandler = authorizedUserPreRoutingFactory(reporting); |
34 | 25 |
|
35 | 26 | function createLegacyPdfRoute({ path, objectType }: { path: string; objectType: string }) { |
36 | 27 | const exportTypeId = 'printablePdf'; |
37 | | - server.route({ |
38 | | - path, |
39 | | - method: 'POST', |
40 | | - options: getStaticFeatureConfig(getRouteConfig, exportTypeId), |
41 | | - handler: async (request: Legacy.Request, h: Legacy.ResponseToolkit) => { |
42 | | - const message = `The following URL is deprecated and will stop working in the next major version: ${request.url.path}`; |
| 28 | + |
| 29 | + router.post( |
| 30 | + { |
| 31 | + path, |
| 32 | + validate: { |
| 33 | + params: schema.object({ |
| 34 | + savedObjectId: schema.string({ minLength: 3 }), |
| 35 | + }), |
| 36 | + query: schema.any(), |
| 37 | + }, |
| 38 | + }, |
| 39 | + |
| 40 | + userHandler(async (user, context, req, res) => { |
| 41 | + const message = `The following URL is deprecated and will stop working in the next major version: ${req.url.path}`; |
43 | 42 | logger.warn(message, ['deprecation']); |
44 | 43 |
|
45 | 44 | try { |
46 | | - const savedObjectId = request.params.savedId; |
47 | | - const queryString = querystring.stringify(request.query); |
| 45 | + const { savedObjectId }: { savedObjectId: string } = req.params as any; |
| 46 | + const queryString = querystring.stringify(req.query as any); |
48 | 47 |
|
49 | 48 | return await handler( |
| 49 | + user, |
50 | 50 | exportTypeId, |
51 | 51 | { |
52 | 52 | objectType, |
53 | 53 | savedObjectId, |
54 | 54 | queryString, |
55 | 55 | }, |
56 | | - request, |
57 | | - h |
| 56 | + context, |
| 57 | + req, |
| 58 | + res |
58 | 59 | ); |
59 | 60 | } catch (err) { |
60 | | - throw handleError(exportTypeId, err); |
| 61 | + throw handleError(res, err); |
61 | 62 | } |
62 | | - }, |
63 | | - }); |
| 63 | + }) |
| 64 | + ); |
64 | 65 | } |
65 | 66 |
|
66 | 67 | createLegacyPdfRoute({ |
|
0 commit comments