Skip to content

Commit 08471cc

Browse files
authored
[Reporting] Remove any types and references to Hapi (#49250)
* [Reporting] Remove any types and references to Hapi * clarification comment * fix import
1 parent 930c156 commit 08471cc

File tree

16 files changed

+135
-79
lines changed

16 files changed

+135
-79
lines changed

x-pack/legacy/plugins/reporting/export_types/png/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface JobDocPayloadPNG extends JobDocPayload {
2121
basePath?: string;
2222
browserTimezone: string;
2323
forceNow?: string;
24-
layout: any;
24+
layout: LayoutInstance;
2525
relativeUrl: string;
2626
objects: undefined;
2727
}

x-pack/legacy/plugins/reporting/server/browsers/download/ensure_downloaded.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { resolve as resolvePath } from 'path';
88
import { existsSync } from 'fs';
99

1010
import { chromium } from '../index';
11-
import { BrowserType } from '../types';
11+
import { BrowserDownload, BrowserType } from '../types';
1212

1313
import { md5 } from './checksum';
1414
import { asyncMap } from './util';
@@ -40,15 +40,7 @@ export async function ensureAllBrowsersDownloaded() {
4040
* @param {BrowserSpec} browsers
4141
* @return {Promise<undefined>}
4242
*/
43-
async function ensureDownloaded(
44-
browsers: Array<{
45-
paths: {
46-
archivesPath: string;
47-
baseUrl: string;
48-
packages: Array<{ archiveFilename: string; archiveChecksum: string }>;
49-
};
50-
}>
51-
) {
43+
async function ensureDownloaded(browsers: BrowserDownload[]) {
5244
await asyncMap(browsers, async browser => {
5345
const { archivesPath } = browser.paths;
5446

x-pack/legacy/plugins/reporting/server/browsers/install.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { LevelLogger as Logger } from '../lib/level_logger';
1212
import { extract } from './extract';
1313
// @ts-ignore
1414
import { md5 } from './download/checksum';
15+
import { BrowserDownload } from './types';
1516

1617
const chmod = promisify(fs.chmod);
1718

@@ -28,7 +29,7 @@ interface PathResponse {
2829
*/
2930
export async function installBrowser(
3031
logger: Logger,
31-
browser: any,
32+
browser: BrowserDownload,
3233
installsPath: string
3334
): Promise<PathResponse> {
3435
const pkg = browser.paths.packages.find((p: Package) => p.platforms.includes(process.platform));

x-pack/legacy/plugins/reporting/server/browsers/types.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,17 @@
55
*/
66

77
export type BrowserType = 'chromium';
8+
9+
export interface BrowserDownload {
10+
paths: {
11+
archivesPath: string;
12+
baseUrl: string;
13+
packages: Array<{
14+
archiveChecksum: string;
15+
archiveFilename: string;
16+
binaryChecksum: string;
17+
binaryRelativePath: string;
18+
platforms: string[];
19+
}>;
20+
};
21+
}

x-pack/legacy/plugins/reporting/server/lib/create_worker.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import { PLUGIN_ID } from '../../common/constants';
8+
import { CancellationToken } from '../../common/cancellation_token';
89
import {
910
ESQueueInstance,
1011
QueueConfig,
@@ -14,6 +15,7 @@ import {
1415
JobDoc,
1516
JobDocPayload,
1617
JobSource,
18+
RequestFacade,
1719
ServerFacade,
1820
} from '../../types';
1921
// @ts-ignore untyped dependency
@@ -39,17 +41,23 @@ function createWorkerFn(server: ServerFacade) {
3941
jobExecutors.set(exportType.jobType, executeJobFactory);
4042
}
4143

42-
const workerFn = (job: JobSource, jobdoc: JobDocPayload | JobDoc, cancellationToken?: any) => {
44+
const workerFn = (
45+
job: JobSource,
46+
arg1: JobDocPayload | JobDoc,
47+
arg2: CancellationToken | RequestFacade | undefined
48+
) => {
4349
// pass the work to the jobExecutor
4450
if (!jobExecutors.get(job._source.jobtype)) {
4551
throw new Error(`Unable to find a job executor for the claimed job: [${job._id}]`);
4652
}
53+
// job executor function signature is different depending on whether it
54+
// is ESQueueWorkerExecuteFn or ImmediateExecuteFn
4755
if (job._id) {
4856
const jobExecutor = jobExecutors.get(job._source.jobtype) as ESQueueWorkerExecuteFn;
49-
return jobExecutor(job._id, jobdoc as JobDoc, cancellationToken);
57+
return jobExecutor(job._id, arg1 as JobDoc, arg2 as CancellationToken);
5058
} else {
5159
const jobExecutor = jobExecutors.get(job._source.jobtype) as ImmediateExecuteFn;
52-
return jobExecutor(null, jobdoc as JobDocPayload, cancellationToken);
60+
return jobExecutor(null, arg1 as JobDocPayload, arg2 as RequestFacade);
5361
}
5462
};
5563
const workerOptions = {

x-pack/legacy/plugins/reporting/server/lib/validate/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@
55
*/
66

77
import { ServerFacade, Logger } from '../../../types';
8+
import { HeadlessChromiumDriverFactory } from '../../browsers/chromium/driver_factory';
89
import { validateBrowser } from './validate_browser';
910
import { validateConfig } from './validate_config';
1011
import { validateMaxContentLength } from './validate_max_content_length';
1112

12-
export async function runValidations(server: ServerFacade, logger: Logger, browserFactory: any) {
13+
export async function runValidations(
14+
server: ServerFacade,
15+
logger: Logger,
16+
browserFactory: HeadlessChromiumDriverFactory
17+
) {
1318
try {
14-
const config = server.config();
1519
await Promise.all([
1620
validateBrowser(server, browserFactory, logger),
17-
validateConfig(config, logger),
21+
validateConfig(server, logger),
1822
validateMaxContentLength(server, logger),
1923
]);
2024
logger.debug(`Reporting plugin self-check ok!`);

x-pack/legacy/plugins/reporting/server/lib/validate/validate_config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
*/
66

77
import crypto from 'crypto';
8-
import { Logger } from '../../../types';
8+
import { ServerFacade, Logger } from '../../../types';
9+
10+
export function validateConfig(serverFacade: ServerFacade, logger: Logger) {
11+
const config = serverFacade.config();
912

10-
export function validateConfig(config: any, logger: Logger) {
1113
const encryptionKey = config.get('xpack.reporting.encryptionKey');
1214
if (encryptionKey == null) {
1315
logger.warning(
1416
`Generating a random key for xpack.reporting.encryptionKey. To prevent pending reports from failing on restart, please set ` +
1517
`xpack.reporting.encryptionKey in kibana.yml`
1618
);
17-
config.set('xpack.reporting.encryptionKey', crypto.randomBytes(16).toString('hex'));
19+
20+
// @ts-ignore: No set() method on KibanaConfig, just get() and has()
21+
config.set('xpack.reporting.encryptionKey', crypto.randomBytes(16).toString('hex')); // update config in memory to contain a usable encryption key
1822
}
1923
}

x-pack/legacy/plugins/reporting/server/lib/validate/validate_max_content_length.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
*/
66
import numeral from '@elastic/numeral';
77
import { defaults, get } from 'lodash';
8-
import { Logger } from '../../../types';
8+
import { Logger, ServerFacade } from '../../../types';
99

1010
const KIBANA_MAX_SIZE_BYTES_PATH = 'xpack.reporting.csv.maxSizeBytes';
1111
const ES_MAX_SIZE_BYTES_PATH = 'http.max_content_length';
1212

13-
export async function validateMaxContentLength(server: any, logger: Logger) {
13+
export async function validateMaxContentLength(server: ServerFacade, logger: Logger) {
1414
const config = server.config();
1515
const { callWithInternalUser } = server.plugins.elasticsearch.getCluster('data');
1616

@@ -22,7 +22,7 @@ export async function validateMaxContentLength(server: any, logger: Logger) {
2222

2323
const elasticSearchMaxContent = get(elasticClusterSettings, 'http.max_content_length', '100mb');
2424
const elasticSearchMaxContentBytes = numeral().unformat(elasticSearchMaxContent.toUpperCase());
25-
const kibanaMaxContentBytes = config.get(KIBANA_MAX_SIZE_BYTES_PATH);
25+
const kibanaMaxContentBytes: number = config.get(KIBANA_MAX_SIZE_BYTES_PATH);
2626

2727
if (kibanaMaxContentBytes > elasticSearchMaxContentBytes) {
2828
logger.warning(

x-pack/legacy/plugins/reporting/server/routes/generate_from_jobparams.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ export function registerGenerateFromJobParams(
7676
const { exportType } = request.params;
7777
let response;
7878
try {
79-
const jobParams = rison.decode(jobParamsRison);
79+
const jobParams = rison.decode(jobParamsRison) as object | null;
80+
if (!jobParams) {
81+
throw new Error('missing jobParams!');
82+
}
8083
response = await handler(exportType, jobParams, request, h);
8184
} catch (err) {
8285
throw boom.badRequest(`invalid rison: ${jobParamsRison}`);

x-pack/legacy/plugins/reporting/server/routes/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function registerRoutes(server: ServerFacade, logger: Logger) {
2626
*/
2727
async function handler(
2828
exportTypeId: string,
29-
jobParams: any,
29+
jobParams: object,
3030
request: RequestFacade,
3131
h: ReportingResponseToolkit
3232
) {

0 commit comments

Comments
 (0)