Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reporting/New Platform] Prepare Typedefs for Legacy Shimming #48825

Merged
merged 18 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/reporting/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

export const PLUGIN_ID = 'reporting';

export const BROWSER_TYPE = 'chromium';

export const JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY =
'xpack.reporting.jobCompletionNotifications';

Expand Down
6 changes: 3 additions & 3 deletions x-pack/legacy/plugins/reporting/common/get_absolute_url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import url from 'url';
// @ts-ignore
import { oncePerServer } from '../server/lib/once_per_server';
import { ConfigObject, KbnServer } from '../types';
import { ServerFacade } from '../types';

function getAbsoluteUrlFn(server: KbnServer) {
const config: ConfigObject = server.config();
function getAbsoluteUrlFn(server: ServerFacade) {
const config = server.config();

return function getAbsoluteUrl({
basePath = config.get('server.basePath'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*/
// @ts-ignore
import { cryptoFactory } from '../../../server/lib/crypto';
import { CryptoFactory, JobDocPayload, KbnServer } from '../../../types';
import { CryptoFactory, JobDocPayload, ServerFacade } from '../../../types';

export const decryptJobHeaders = async ({
job,
server,
}: {
job: JobDocPayload;
server: KbnServer;
server: ServerFacade;
}) => {
const crypto: CryptoFactory = cryptoFactory(server);
const decryptedHeaders: string = await crypto.decrypt(job.headers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { ConditionalHeaders, ConfigObject, JobDocPayload, KbnServer } from '../../../types';
import { ConditionalHeaders, JobDocPayload, ServerFacade } from '../../../types';

export const getConditionalHeaders = ({
job,
Expand All @@ -12,9 +12,9 @@ export const getConditionalHeaders = ({
}: {
job: JobDocPayload;
filteredHeaders: Record<string, string>;
server: KbnServer;
server: ServerFacade;
}) => {
const config: ConfigObject = server.config();
const config = server.config();
const [hostname, port, basePath, protocol] = [
config.get('xpack.reporting.kibanaServer.hostname') || config.get('server.host'),
config.get('xpack.reporting.kibanaServer.port') || config.get('server.port'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { UI_SETTINGS_CUSTOM_PDF_LOGO } from '../../../common/constants';
import { ConditionalHeaders, KbnServer } from '../../../types';
import { ConditionalHeaders, ServerFacade } from '../../../types';
import { JobDocPayloadPDF } from '../../printable_pdf/types'; // Logo is PDF only

export const getCustomLogo = async ({
Expand All @@ -15,7 +15,7 @@ export const getCustomLogo = async ({
}: {
job: JobDocPayloadPDF;
conditionalHeaders: ConditionalHeaders;
server: KbnServer;
server: ServerFacade;
}) => {
const serverBasePath: string = server.config().get('server.basePath');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from 'url';
import { getAbsoluteUrlFactory } from '../../../common/get_absolute_url';
import { validateUrls } from '../../../common/validate_urls';
import { KbnServer } from '../../../types';
import { ServerFacade } from '../../../types';
import { JobDocPayloadPNG } from '../../png/types';
import { JobDocPayloadPDF } from '../../printable_pdf/types';

Expand All @@ -26,7 +26,7 @@ export async function getFullUrls({
...mergeValues // pass-throughs
}: {
job: JobDocPayloadPNG | JobDocPayloadPDF;
server: KbnServer;
server: ServerFacade;
}) {
const getAbsoluteUrl = getAbsoluteUrlFactory(server);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import { omit } from 'lodash';
import { KBN_SCREENSHOT_HEADER_BLACKLIST } from '../../../common/constants';
import { JobDocPayload, KbnServer } from '../../../types';
import { JobDocPayload, ServerFacade } from '../../../types';

export const omitBlacklistedHeaders = ({
job,
Expand All @@ -14,7 +14,7 @@ export const omitBlacklistedHeaders = ({
}: {
job: JobDocPayload;
decryptedHeaders: Record<string, string>;
server: KbnServer;
server: ServerFacade;
}) => {
const filteredHeaders: Record<string, string> = omit(
decryptedHeaders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { KbnServer } from '../../../types';
import { ServerFacade } from '../../../types';
import { LayoutTypes } from '../constants';
import { Layout, LayoutParams } from './layout';
import { PreserveLayout } from './preserve_layout';
import { PrintLayout } from './print_layout';

export function createLayout(server: KbnServer, layoutParams?: LayoutParams): Layout {
export function createLayout(server: ServerFacade, layoutParams?: LayoutParams): Layout {
if (layoutParams && layoutParams.id === LayoutTypes.PRESERVE_LAYOUT) {
return new PreserveLayout(layoutParams.dimensions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import path from 'path';
import { EvaluateFn, SerializableOrJSHandle } from 'puppeteer';
import { LevelLogger } from '../../../server/lib';
import { HeadlessChromiumDriver } from '../../../server/browsers/chromium/driver';
import { KbnServer } from '../../../types';
import { ServerFacade } from '../../../types';
import { LayoutTypes } from '../constants';
import { getDefaultLayoutSelectors, Layout, LayoutSelectorDictionary, Size } from './layout';
import { CaptureConfig } from './types';
Expand All @@ -20,7 +20,7 @@ export class PrintLayout extends Layout {
public readonly groupCount = 2;
private captureConfig: CaptureConfig;

constructor(server: KbnServer) {
constructor(server: ServerFacade) {
super(LayoutTypes.PRINT);
this.captureConfig = server.config().get('xpack.reporting.capture');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import * as Rx from 'rxjs';
import { first, mergeMap } from 'rxjs/operators';
import { KbnServer } from '../../../../types';
import { ServerFacade } from '../../../../types';
import { HeadlessChromiumDriverFactory } from '../../../../server/browsers/chromium/driver_factory';
import { HeadlessChromiumDriver as HeadlessBrowser } from '../../../../server/browsers/chromium/driver';
import {
Expand All @@ -33,7 +33,7 @@ interface ScreenshotResults {
screenshots: Screenshot[];
}

export function screenshotsObservableFactory(server: KbnServer) {
export function screenshotsObservableFactory(server: ServerFacade) {
const browserDriverFactory: HeadlessChromiumDriverFactory = server.plugins.reporting.browserDriverFactory; // prettier-ignore
const config = server.config();
const captureConfig = config.get('xpack.reporting.capture');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Request } from 'hapi';
import { oncePerServer } from '../../../server/lib/once_per_server';
import { cryptoFactory } from '../../../server/lib/crypto';
import { KbnServer, ConditionalHeaders, CreateJobFactory } from '../../../types';
import { ConditionalHeaders, CreateJobFactory, ServerFacade, RequestFacade } from '../../../types';
import { JobParamsDiscoverCsv, ESQueueCreateJobFnDiscoverCsv } from '../types';

function createJobFn(server: KbnServer) {
function createJobFn(server: ServerFacade) {
const crypto = cryptoFactory(server);

return async function createJob(
jobParams: JobParamsDiscoverCsv,
headers: ConditionalHeaders,
request: Request
request: RequestFacade
) {
const serializedEncryptedHeaders = await crypto.encrypt(headers);

Expand All @@ -36,5 +35,5 @@ function createJobFn(server: KbnServer) {
}

export const createJobFactory: CreateJobFactory = oncePerServer(createJobFn as (
server: KbnServer
server: ServerFacade
) => ESQueueCreateJobFnDiscoverCsv);
5 changes: 2 additions & 3 deletions x-pack/legacy/plugins/reporting/export_types/csv/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Request } from 'hapi';
import { JobDocPayload, JobParamPostPayload, ConditionalHeaders } from '../../types';
import { JobDocPayload, JobParamPostPayload, ConditionalHeaders, RequestFacade } from '../../types';

export interface JobParamPostPayloadDiscoverCsv extends JobParamPostPayload {
state?: {
Expand All @@ -30,5 +29,5 @@ export interface JobDocPayloadDiscoverCsv extends JobDocPayload {
export type ESQueueCreateJobFnDiscoverCsv = (
jobParams: JobParamsDiscoverCsv,
headers: ConditionalHeaders,
request: Request
request: RequestFacade
) => Promise<JobParamsDiscoverCsv>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
*/

import { notFound, notImplemented } from 'boom';
import { Request } from 'hapi';
import { get } from 'lodash';

import { PLUGIN_ID, CSV_FROM_SAVEDOBJECT_JOB_TYPE } from '../../../../common/constants';
import { cryptoFactory, LevelLogger, oncePerServer } from '../../../../server/lib';
import { KbnServer } from '../../../../types';
import { ServerFacade, RequestFacade } from '../../../../types';
import {
SavedObject,
SavedObjectServiceError,
Expand All @@ -32,10 +30,10 @@ interface VisData {
type CreateJobFn = (
jobParams: JobParamsPanelCsv,
headers: any,
req: Request
req: RequestFacade
) => Promise<JobDocPayloadPanelCsv>;

function createJobFn(server: KbnServer): CreateJobFn {
function createJobFn(server: ServerFacade): CreateJobFn {
const crypto = cryptoFactory(server);
const logger = LevelLogger.createForServer(server, [
PLUGIN_ID,
Expand All @@ -46,7 +44,7 @@ function createJobFn(server: KbnServer): CreateJobFn {
return async function createJob(
jobParams: JobParamsPanelCsv,
headers: any,
req: Request
req: RequestFacade
): Promise<JobDocPayloadPanelCsv> {
const { savedObjectType, savedObjectId } = jobParams;
const serializedEncryptedHeaders = await crypto.encrypt(headers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Request } from 'hapi';
import { i18n } from '@kbn/i18n';

import { cryptoFactory, LevelLogger, oncePerServer } from '../../../server/lib';
import { JobDocOutputExecuted, KbnServer, ExecuteImmediateJobFactory } from '../../../types';
import {
JobDocOutputExecuted,
ServerFacade,
ExecuteImmediateJobFactory,
RequestFacade,
} from '../../../types';
import {
CONTENT_TYPE_CSV,
CSV_FROM_SAVEDOBJECT_JOB_TYPE,
Expand All @@ -20,10 +23,10 @@ import { createGenerateCsv } from './lib';
type ExecuteJobFn = (
jobId: string | null,
job: JobDocPayloadPanelCsv,
realRequest?: Request
realRequest?: RequestFacade
) => Promise<JobDocOutputExecuted>;

function executeJobFactoryFn(server: KbnServer): ExecuteJobFn {
function executeJobFactoryFn(server: ServerFacade): ExecuteJobFn {
const crypto = cryptoFactory(server);
const logger = LevelLogger.createForServer(server, [
PLUGIN_ID,
Expand All @@ -34,7 +37,7 @@ function executeJobFactoryFn(server: KbnServer): ExecuteJobFn {
return async function executeJob(
jobId: string | null,
job: JobDocPayloadPanelCsv,
realRequest?: Request
realRequest?: RequestFacade
): Promise<JobDocOutputExecuted> {
// There will not be a jobID for "immediate" generation.
// jobID is only for "queued" jobs
Expand All @@ -46,7 +49,7 @@ function executeJobFactoryFn(server: KbnServer): ExecuteJobFn {

jobLogger.debug(`Execute job generating [${visType}] csv`);

let requestObject: Request | FakeRequest;
let requestObject: RequestFacade | FakeRequest;
if (isImmediate && realRequest) {
jobLogger.info(`Executing job from immediate API`);
requestObject = realRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
*/

import { badRequest } from 'boom';
import { Request } from 'hapi';
import { KbnServer, Logger } from '../../../../types';
import { SearchPanel, VisPanel, JobParamsPanelCsv } from '../../types';
import { FakeRequest } from '../../types';
import { ServerFacade, RequestFacade, Logger } from '../../../../types';
import { SearchPanel, VisPanel, JobParamsPanelCsv, FakeRequest } from '../../types';
import { generateCsvSearch } from './generate_csv_search';

export function createGenerateCsv(logger: Logger) {
return async function generateCsv(
request: Request | FakeRequest,
server: KbnServer,
request: RequestFacade | FakeRequest,
server: ServerFacade,
visType: string,
panel: VisPanel | SearchPanel,
jobParams: JobParamsPanelCsv
Expand All @@ -27,7 +25,7 @@ export function createGenerateCsv(logger: Logger) {
switch (visType) {
case 'search':
return await generateCsvSearch(
request as Request,
request as RequestFacade,
server,
logger,
panel as SearchPanel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Request } from 'hapi';

import { buildEsQuery } from '@kbn/es-query';
// @ts-ignore no module definition
import { createGenerateCsv } from '../../../csv/server/lib/generate_csv';

import { CancellationToken } from '../../../../common/cancellation_token';

import { KbnServer, Logger } from '../../../../types';
import { ServerFacade, RequestFacade, Logger } from '../../../../types';
import {
IndexPatternSavedObject,
SavedSearchObjectAttributes,
Expand Down Expand Up @@ -50,8 +46,8 @@ const getUiSettings = async (config: any) => {
};

export async function generateCsvSearch(
req: Request,
server: KbnServer,
req: RequestFacade,
server: ServerFacade,
logger: Logger,
searchPanel: SearchPanel,
jobParams: JobParamsDiscoverCsv
Expand Down Expand Up @@ -140,7 +136,7 @@ export async function generateCsvSearch(
},
};
const { callWithRequest } = server.plugins.elasticsearch.getCluster('data');
const callCluster = (...params: any[]) => callWithRequest(req, ...params);
const callCluster = (...params: [string, object]) => callWithRequest(req, ...params);
const config = server.config();
const uiSettings = await getUiSettings(uiConfig);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Request } from 'hapi';
import { RequestFacade } from '../../../../types';
import { JobParamsPostPayloadPanelCsv, JobParamsPanelCsv } from '../../types';

export function getJobParamsFromRequest(
request: Request,
request: RequestFacade,
opts: { isImmediate: boolean }
): Partial<JobParamsPanelCsv> {
const { savedObjectType, savedObjectId } = request.params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/

import { CancellationToken } from '../../common/cancellation_token';
import { JobParamPostPayload, JobDocPayload, KbnServer } from '../../types';
import { JobParamPostPayload, JobDocPayload, ServerFacade } from '../../types';

export interface FakeRequest {
headers: any;
server: KbnServer;
server: ServerFacade;
}

export interface JobParamsPostPayloadPanelCsv extends JobParamPostPayload {
Expand Down
Loading