From d4fd2a39ea1ef169a1575446ff3bb47563aab21f Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Mon, 18 May 2020 10:53:01 -0700 Subject: [PATCH] Revert touching routes code --- .../server/routes/generate_from_jobparams.ts | 9 +++--- .../routes/generate_from_savedobject.ts | 16 +++++------ .../generate_from_savedobject_immediate.ts | 7 +++-- .../server/routes/generation.test.ts | 4 +-- .../reporting/server/routes/generation.ts | 7 +++-- .../plugins/reporting/server/routes/index.ts | 4 +-- .../plugins/reporting/server/routes/jobs.ts | 9 +++--- .../routes/lib/authorized_user_pre_routing.ts | 4 +-- .../server/routes/lib/make_request_facade.ts | 2 +- .../lib/reporting_feature_pre_routing.ts | 4 +-- .../routes/lib/route_config_factories.ts | 12 ++++---- .../reporting/server/routes/types.d.ts | 28 +++++++++++++++++++ .../legacy/plugins/reporting/server/types.ts | 18 ------------ 13 files changed, 69 insertions(+), 55 deletions(-) create mode 100644 x-pack/legacy/plugins/reporting/server/routes/types.d.ts diff --git a/x-pack/legacy/plugins/reporting/server/routes/generate_from_jobparams.ts b/x-pack/legacy/plugins/reporting/server/routes/generate_from_jobparams.ts index d2e5bd07fbc71..70a1a32e76a65 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/generate_from_jobparams.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/generate_from_jobparams.ts @@ -10,14 +10,15 @@ import { Legacy } from 'kibana'; import rison from 'rison-node'; import { ReportingCore } from '../'; import { API_BASE_URL } from '../../common/constants'; -import { LevelLogger } from '../lib'; -import { HandlerErrorFunction, HandlerFunction, ReportingSetupDeps, ServerFacade } from '../types'; +import { LevelLogger as Logger } from '../lib'; +import { ReportingSetupDeps, ServerFacade } from '../types'; import { makeRequestFacade } from './lib/make_request_facade'; import { GetRouteConfigFactoryFn, getRouteConfigFactoryReportingPre, RouteConfigFactory, } from './lib/route_config_factories'; +import { HandlerErrorFunction, HandlerFunction, ReportingResponseToolkit } from './types'; const BASE_GENERATE = `${API_BASE_URL}/generate`; @@ -27,7 +28,7 @@ export function registerGenerateFromJobParams( plugins: ReportingSetupDeps, handler: HandlerFunction, handleError: HandlerErrorFunction, - logger: LevelLogger + logger: Logger ) { const config = reporting.getConfig(); const getRouteConfig = () => { @@ -63,7 +64,7 @@ export function registerGenerateFromJobParams( path: `${BASE_GENERATE}/{exportType}`, method: 'POST', options: getRouteConfig(), - handler: async (legacyRequest: Legacy.Request, h: Legacy.ResponseToolkit) => { + handler: async (legacyRequest: Legacy.Request, h: ReportingResponseToolkit) => { const request = makeRequestFacade(legacyRequest); let jobParamsRison: string | null; diff --git a/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject.ts b/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject.ts index 7cf847ffe681a..03a893d1abeb4 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject.ts @@ -9,16 +9,16 @@ import { get } from 'lodash'; import { ReportingCore } from '../'; import { API_BASE_GENERATE_V1, CSV_FROM_SAVEDOBJECT_JOB_TYPE } from '../../common/constants'; import { getJobParamsFromRequest } from '../../export_types/csv_from_savedobject/server/lib/get_job_params_from_request'; -import { LevelLogger } from '../lib'; +import { LevelLogger as Logger } from '../lib'; +import { ReportingSetupDeps, ServerFacade } from '../types'; +import { makeRequestFacade } from './lib/make_request_facade'; +import { getRouteOptionsCsv } from './lib/route_config_factories'; import { HandlerErrorFunction, HandlerFunction, QueuedJobPayload, - ReportingSetupDeps, - ServerFacade, -} from '../types'; -import { makeRequestFacade } from './lib/make_request_facade'; -import { getRouteOptionsCsv } from './lib/route_config_factories'; + ReportingResponseToolkit, +} from './types'; /* * This function registers API Endpoints for queuing Reporting jobs. The API inputs are: @@ -35,7 +35,7 @@ export function registerGenerateCsvFromSavedObject( plugins: ReportingSetupDeps, handleRoute: HandlerFunction, handleRouteError: HandlerErrorFunction, - logger: LevelLogger + logger: Logger ) { const config = reporting.getConfig(); const routeOptions = getRouteOptionsCsv(config, plugins, logger); @@ -44,7 +44,7 @@ export function registerGenerateCsvFromSavedObject( path: `${API_BASE_GENERATE_V1}/csv/saved-object/{savedObjectType}:{savedObjectId}`, method: 'POST', options: routeOptions, - handler: async (legacyRequest: Legacy.Request, h: Legacy.ResponseToolkit) => { + handler: async (legacyRequest: Legacy.Request, h: ReportingResponseToolkit) => { const requestFacade = makeRequestFacade(legacyRequest); /* diff --git a/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject_immediate.ts b/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject_immediate.ts index 8a36d4d85c61a..22aebb05cdf49 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject_immediate.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject_immediate.ts @@ -11,10 +11,11 @@ import { API_BASE_GENERATE_V1 } from '../../common/constants'; import { createJobFactory, executeJobFactory } from '../../export_types/csv_from_savedobject'; import { getJobParamsFromRequest } from '../../export_types/csv_from_savedobject/server/lib/get_job_params_from_request'; import { JobDocPayloadPanelCsv } from '../../export_types/csv_from_savedobject/types'; -import { LevelLogger } from '../lib'; +import { LevelLogger as Logger } from '../lib'; import { JobDocOutput, ReportingSetupDeps, ServerFacade } from '../types'; import { makeRequestFacade } from './lib/make_request_facade'; import { getRouteOptionsCsv } from './lib/route_config_factories'; +import { ReportingResponseToolkit } from './types'; type ResponseFacade = ResponseObject & { isBoom: boolean; @@ -33,7 +34,7 @@ export function registerGenerateCsvFromSavedObjectImmediate( reporting: ReportingCore, server: ServerFacade, plugins: ReportingSetupDeps, - parentLogger: LevelLogger + parentLogger: Logger ) { const config = reporting.getConfig(); const routeOptions = getRouteOptionsCsv(config, plugins, parentLogger); @@ -47,7 +48,7 @@ export function registerGenerateCsvFromSavedObjectImmediate( path: `${API_BASE_GENERATE_V1}/immediate/csv/saved-object/{savedObjectType}:{savedObjectId}`, method: 'POST', options: routeOptions, - handler: async (legacyRequest: Legacy.Request, h: Legacy.ResponseToolkit) => { + handler: async (legacyRequest: Legacy.Request, h: ReportingResponseToolkit) => { const request = makeRequestFacade(legacyRequest); const logger = parentLogger.clone(['savedobject-csv']); const jobParams = getJobParamsFromRequest(request, { isImmediate: true }); diff --git a/x-pack/legacy/plugins/reporting/server/routes/generation.test.ts b/x-pack/legacy/plugins/reporting/server/routes/generation.test.ts index e4cccd854c829..74401f8228f7d 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/generation.test.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/generation.test.ts @@ -7,7 +7,7 @@ import Hapi from 'hapi'; import { ReportingConfig, ReportingCore } from '../'; import { createMockReportingCore } from '../../test_helpers'; -import { LevelLogger } from '../lib'; +import { LevelLogger as Logger } from '../lib'; import { ReportingSetupDeps, ServerFacade } from '../types'; import { registerJobGenerationRoutes } from './generation'; @@ -27,7 +27,7 @@ let mockReportingConfig: ReportingConfig; const mockLogger = ({ error: jest.fn(), debug: jest.fn(), -} as unknown) as LevelLogger; +} as unknown) as Logger; beforeEach(async () => { mockServer = new Hapi.Server({ diff --git a/x-pack/legacy/plugins/reporting/server/routes/generation.ts b/x-pack/legacy/plugins/reporting/server/routes/generation.ts index 4412b6fe49dcd..56faa37d5fcbd 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/generation.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/generation.ts @@ -9,12 +9,13 @@ import { errors as elasticsearchErrors } from 'elasticsearch'; import { Legacy } from 'kibana'; import { ReportingCore } from '../'; import { API_BASE_URL } from '../../common/constants'; -import { LevelLogger } from '../lib'; +import { LevelLogger as Logger } from '../lib'; import { ReportingSetupDeps, ServerFacade } from '../types'; import { registerGenerateFromJobParams } from './generate_from_jobparams'; import { registerGenerateCsvFromSavedObject } from './generate_from_savedobject'; import { registerGenerateCsvFromSavedObjectImmediate } from './generate_from_savedobject_immediate'; import { makeRequestFacade } from './lib/make_request_facade'; +import { ReportingResponseToolkit } from './types'; const esErrors = elasticsearchErrors as Record; @@ -22,7 +23,7 @@ export function registerJobGenerationRoutes( reporting: ReportingCore, server: ServerFacade, plugins: ReportingSetupDeps, - logger: LevelLogger + logger: Logger ) { const config = reporting.getConfig(); const downloadBaseUrl = @@ -35,7 +36,7 @@ export function registerJobGenerationRoutes( exportTypeId: string, jobParams: object, legacyRequest: Legacy.Request, - h: Legacy.ResponseToolkit + h: ReportingResponseToolkit ) { const request = makeRequestFacade(legacyRequest); const user = request.pre.user; diff --git a/x-pack/legacy/plugins/reporting/server/routes/index.ts b/x-pack/legacy/plugins/reporting/server/routes/index.ts index 4a9f60ca8dbe2..556f4e12b077e 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/index.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/index.ts @@ -5,7 +5,7 @@ */ import { ReportingCore } from '../'; -import { LevelLogger } from '../lib'; +import { LevelLogger as Logger } from '../lib'; import { ReportingSetupDeps, ServerFacade } from '../types'; import { registerJobGenerationRoutes } from './generation'; import { registerJobInfoRoutes } from './jobs'; @@ -14,7 +14,7 @@ export function registerRoutes( reporting: ReportingCore, server: ServerFacade, plugins: ReportingSetupDeps, - logger: LevelLogger + logger: Logger ) { registerJobGenerationRoutes(reporting, server, plugins, logger); registerJobInfoRoutes(reporting, server, plugins, logger); diff --git a/x-pack/legacy/plugins/reporting/server/routes/jobs.ts b/x-pack/legacy/plugins/reporting/server/routes/jobs.ts index 5d1e6fc43f49d..59090961998af 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/jobs.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/jobs.ts @@ -9,7 +9,7 @@ import { ResponseObject } from 'hapi'; import { Legacy } from 'kibana'; import { ReportingCore } from '../'; import { API_BASE_URL } from '../../common/constants'; -import { LevelLogger } from '../lib'; +import { LevelLogger as Logger } from '../lib'; import { jobsQueryFactory } from '../lib/jobs_query'; import { JobDocOutput, JobSource, ReportingSetupDeps, ServerFacade } from '../types'; import { @@ -22,6 +22,7 @@ import { getRouteConfigFactoryDownloadPre, getRouteConfigFactoryManagementPre, } from './lib/route_config_factories'; +import { ReportingResponseToolkit } from './types'; interface ListQuery { page: string; @@ -38,7 +39,7 @@ export function registerJobInfoRoutes( reporting: ReportingCore, server: ServerFacade, plugins: ReportingSetupDeps, - logger: LevelLogger + logger: Logger ) { const config = reporting.getConfig(); const { elasticsearch } = plugins; @@ -147,7 +148,7 @@ export function registerJobInfoRoutes( path: `${MAIN_ENTRY}/download/{docId}`, method: 'GET', options: getRouteConfigDownload(), - handler: async (legacyRequest: Legacy.Request, h: Legacy.ResponseToolkit) => { + handler: async (legacyRequest: Legacy.Request, h: ReportingResponseToolkit) => { const request = makeRequestFacade(legacyRequest); const { docId } = request.params; @@ -187,7 +188,7 @@ export function registerJobInfoRoutes( path: `${MAIN_ENTRY}/delete/{docId}`, method: 'DELETE', options: getRouteConfigDelete(), - handler: async (legacyRequest: Legacy.Request, h: Legacy.ResponseToolkit) => { + handler: async (legacyRequest: Legacy.Request, h: ReportingResponseToolkit) => { const request = makeRequestFacade(legacyRequest); const { docId } = request.params; diff --git a/x-pack/legacy/plugins/reporting/server/routes/lib/authorized_user_pre_routing.ts b/x-pack/legacy/plugins/reporting/server/routes/lib/authorized_user_pre_routing.ts index b925e2f9680bc..0d297a60a3559 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/lib/authorized_user_pre_routing.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/lib/authorized_user_pre_routing.ts @@ -8,7 +8,7 @@ import Boom from 'boom'; import { Legacy } from 'kibana'; import { AuthenticatedUser } from '../../../../../../plugins/security/server'; import { ReportingConfig } from '../../../server'; -import { LevelLogger } from '../../../server/lib'; +import { LevelLogger as Logger } from '../../../server/lib'; import { ReportingSetupDeps } from '../../../server/types'; import { getUserFactory } from '../../lib/get_user'; @@ -21,7 +21,7 @@ export type PreRoutingFunction = ( export const authorizedUserPreRoutingFactory = function authorizedUserPreRoutingFn( config: ReportingConfig, plugins: ReportingSetupDeps, - logger: LevelLogger + logger: Logger ) { const getUser = getUserFactory(plugins.security, logger); const { info: xpackInfo } = plugins.__LEGACY.plugins.xpack_main; diff --git a/x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts b/x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts index d2c5a8c9c096a..5dd62711f2565 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts @@ -7,10 +7,10 @@ import { RequestQuery } from 'hapi'; import { Legacy } from 'kibana'; import { + RequestFacade, ReportingRequestPayload, ReportingRequestPre, ReportingRequestQuery, - RequestFacade, } from '../../../server/types'; export function makeRequestFacade(request: Legacy.Request): RequestFacade { diff --git a/x-pack/legacy/plugins/reporting/server/routes/lib/reporting_feature_pre_routing.ts b/x-pack/legacy/plugins/reporting/server/routes/lib/reporting_feature_pre_routing.ts index 4dc410403391e..f9c7571e25bac 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/lib/reporting_feature_pre_routing.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/lib/reporting_feature_pre_routing.ts @@ -7,7 +7,7 @@ import Boom from 'boom'; import { Legacy } from 'kibana'; import { ReportingConfig } from '../../'; -import { LevelLogger } from '../../lib'; +import { LevelLogger as Logger } from '../../lib'; import { ReportingSetupDeps } from '../../types'; export type GetReportingFeatureIdFn = (request: Legacy.Request) => string; @@ -15,7 +15,7 @@ export type GetReportingFeatureIdFn = (request: Legacy.Request) => string; export const reportingFeaturePreRoutingFactory = function reportingFeaturePreRoutingFn( config: ReportingConfig, plugins: ReportingSetupDeps, - logger: LevelLogger + logger: Logger ) { const xpackMainPlugin = plugins.__LEGACY.plugins.xpack_main; const pluginId = 'reporting'; diff --git a/x-pack/legacy/plugins/reporting/server/routes/lib/route_config_factories.ts b/x-pack/legacy/plugins/reporting/server/routes/lib/route_config_factories.ts index 337a683622683..0ee9db4678684 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/lib/route_config_factories.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/lib/route_config_factories.ts @@ -6,7 +6,7 @@ import Joi from 'joi'; import { ReportingConfig } from '../../'; -import { LevelLogger } from '../../lib'; +import { LevelLogger as Logger } from '../../lib'; import { CSV_FROM_SAVEDOBJECT_JOB_TYPE } from '../../../common/constants'; import { ReportingSetupDeps } from '../../types'; import { authorizedUserPreRoutingFactory } from './authorized_user_pre_routing'; @@ -32,7 +32,7 @@ export type GetRouteConfigFactoryFn = ( export function getRouteConfigFactoryReportingPre( config: ReportingConfig, plugins: ReportingSetupDeps, - logger: LevelLogger + logger: Logger ): GetRouteConfigFactoryFn { const authorizedUserPreRouting = authorizedUserPreRoutingFactory(config, plugins, logger); const reportingFeaturePreRouting = reportingFeaturePreRoutingFactory(config, plugins, logger); @@ -53,7 +53,7 @@ export function getRouteConfigFactoryReportingPre( export function getRouteOptionsCsv( config: ReportingConfig, plugins: ReportingSetupDeps, - logger: LevelLogger + logger: Logger ) { const getRouteConfig = getRouteConfigFactoryReportingPre(config, plugins, logger); return { @@ -78,7 +78,7 @@ export function getRouteOptionsCsv( export function getRouteConfigFactoryManagementPre( config: ReportingConfig, plugins: ReportingSetupDeps, - logger: LevelLogger + logger: Logger ): GetRouteConfigFactoryFn { const authorizedUserPreRouting = authorizedUserPreRoutingFactory(config, plugins, logger); const reportingFeaturePreRouting = reportingFeaturePreRoutingFactory(config, plugins, logger); @@ -102,7 +102,7 @@ export function getRouteConfigFactoryManagementPre( export function getRouteConfigFactoryDownloadPre( config: ReportingConfig, plugins: ReportingSetupDeps, - logger: LevelLogger + logger: Logger ): GetRouteConfigFactoryFn { const getManagementRouteConfig = getRouteConfigFactoryManagementPre(config, plugins, logger); return (): RouteConfigFactory => ({ @@ -117,7 +117,7 @@ export function getRouteConfigFactoryDownloadPre( export function getRouteConfigFactoryDeletePre( config: ReportingConfig, plugins: ReportingSetupDeps, - logger: LevelLogger + logger: Logger ): GetRouteConfigFactoryFn { const getManagementRouteConfig = getRouteConfigFactoryManagementPre(config, plugins, logger); return (): RouteConfigFactory => ({ diff --git a/x-pack/legacy/plugins/reporting/server/routes/types.d.ts b/x-pack/legacy/plugins/reporting/server/routes/types.d.ts new file mode 100644 index 0000000000000..2ebe1ada418dc --- /dev/null +++ b/x-pack/legacy/plugins/reporting/server/routes/types.d.ts @@ -0,0 +1,28 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { Legacy } from 'kibana'; +import { JobDocPayload } from '../types'; + +export type HandlerFunction = ( + exportType: string, + jobParams: object, + request: Legacy.Request, + h: ReportingResponseToolkit +) => any; + +export type HandlerErrorFunction = (exportType: string, err: Error) => any; + +export interface QueuedJobPayload { + error?: boolean; + source: { + job: { + payload: JobDocPayload; + }; + }; +} + +export type ReportingResponseToolkit = Legacy.ResponseToolkit; diff --git a/x-pack/legacy/plugins/reporting/server/types.ts b/x-pack/legacy/plugins/reporting/server/types.ts index 85b25d083d787..1417f1d7b50cb 100644 --- a/x-pack/legacy/plugins/reporting/server/types.ts +++ b/x-pack/legacy/plugins/reporting/server/types.ts @@ -50,13 +50,6 @@ export interface GenerateExportTypePayload { export type ReportingRequestPayload = GenerateExportTypePayload | JobParamPostPayload; -export type HandlerFunction = ( - exportType: string, - jobParams: object, - request: Legacy.Request, - h: Legacy.ResponseToolkit -) => any; - export interface TimeRangeParams { timezone: string; min: Date | string | number; @@ -67,8 +60,6 @@ export interface JobParamPostPayload { timerange: TimeRangeParams; } -export type HandlerErrorFunction = (exportType: string, err: Error) => any; - export interface JobDocPayload { headers?: string; // serialized encrypted headers jobParams: JobParamsType; @@ -76,15 +67,6 @@ export interface JobDocPayload { type: string | null; } -export interface QueuedJobPayload { - error?: boolean; - source: { - job: { - payload: JobDocPayload; - }; - }; -} - export interface JobSource { _id: string; _index: string;