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] Rename export type definitions for Task Manager #65213

Merged
merged 1 commit into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all 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: 0 additions & 2 deletions x-pack/plugins/reporting/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ export class ReportingPublicPlugin implements Plugin<void, void> {
);
}

// FIXME: only perform these actions for authenticated routes
// Depends on https://github.com/elastic/kibana/pull/39477
public start(core: CoreStart) {
const { http, notifications } = core;
const apiClient = new ReportingAPIClient(http);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ interface HasEncryptedHeaders {
// TODO merge functionality with CSV execute job
export const decryptJobHeaders = async <
JobParamsType,
JobDocPayloadType extends HasEncryptedHeaders
ScheduledTaskParamsType extends HasEncryptedHeaders
>({
encryptionKey,
job,
logger,
}: {
encryptionKey?: string;
job: JobDocPayloadType;
job: ScheduledTaskParamsType;
logger: LevelLogger;
}): Promise<Record<string, string>> => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import sinon from 'sinon';
import { ReportingConfig } from '../../../';
import { ReportingCore } from '../../../core';
import { createMockReportingCore } from '../../../test_helpers';
import { JobDocPayload } from '../../../types';
import { JobDocPayloadPDF } from '../../printable_pdf/types';
import { ScheduledTaskParams } from '../../../types';
import { ScheduledTaskParamsPDF } from '../../printable_pdf/types';
import { getConditionalHeaders, getCustomLogo } from './index';

let mockConfig: ReportingConfig;
Expand Down Expand Up @@ -37,7 +37,7 @@ describe('conditions', () => {
};

const conditionalHeaders = await getConditionalHeaders({
job: {} as JobDocPayload<any>,
job: {} as ScheduledTaskParams<any>,
filteredHeaders: permittedHeaders,
config: mockConfig,
});
Expand All @@ -64,14 +64,14 @@ test('uses basePath from job when creating saved object service', async () => {
baz: 'quix',
};
const conditionalHeaders = await getConditionalHeaders({
job: {} as JobDocPayload<any>,
job: {} as ScheduledTaskParams<any>,
filteredHeaders: permittedHeaders,
config: mockConfig,
});
const jobBasePath = '/sbp/s/marketing';
await getCustomLogo({
reporting: mockReportingPlugin,
job: { basePath: jobBasePath } as JobDocPayloadPDF,
job: { basePath: jobBasePath } as ScheduledTaskParamsPDF,
conditionalHeaders,
config: mockConfig,
});
Expand All @@ -94,14 +94,14 @@ test(`uses basePath from server if job doesn't have a basePath when creating sav
baz: 'quix',
};
const conditionalHeaders = await getConditionalHeaders({
job: {} as JobDocPayload<any>,
job: {} as ScheduledTaskParams<any>,
filteredHeaders: permittedHeaders,
config: mockConfig,
});

await getCustomLogo({
reporting: mockReportingPlugin,
job: {} as JobDocPayloadPDF,
job: {} as ScheduledTaskParamsPDF,
conditionalHeaders,
config: mockConfig,
});
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('config formatting', () => {
mockConfig = getMockConfig(mockConfigGet);

const conditionalHeaders = await getConditionalHeaders({
job: {} as JobDocPayload<any>,
job: {} as ScheduledTaskParams<any>,
filteredHeaders: {},
config: mockConfig,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import { ReportingConfig } from '../../../';
import { ConditionalHeaders } from '../../../types';

export const getConditionalHeaders = <JobDocPayloadType>({
export const getConditionalHeaders = <ScheduledTaskParamsType>({
config,
job,
filteredHeaders,
}: {
config: ReportingConfig;
job: JobDocPayloadType;
job: ScheduledTaskParamsType;
filteredHeaders: Record<string, string>;
}) => {
const { kbnConfig } = config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { ReportingCore } from '../../../core';
import { createMockReportingCore } from '../../../test_helpers';
import { JobDocPayloadPDF } from '../../printable_pdf/types';
import { ScheduledTaskParamsPDF } from '../../printable_pdf/types';
import { getConditionalHeaders, getCustomLogo } from './index';

const mockConfigGet = jest.fn().mockImplementation((key: string) => {
Expand Down Expand Up @@ -37,15 +37,15 @@ test(`gets logo from uiSettings`, async () => {
});

const conditionalHeaders = await getConditionalHeaders({
job: {} as JobDocPayloadPDF,
job: {} as ScheduledTaskParamsPDF,
filteredHeaders: permittedHeaders,
config: mockConfig,
});

const { logo } = await getCustomLogo({
reporting: mockReportingPlugin,
config: mockConfig,
job: {} as JobDocPayloadPDF,
job: {} as ScheduledTaskParamsPDF,
conditionalHeaders,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { ReportingConfig, ReportingCore } from '../../../';
import { UI_SETTINGS_CUSTOM_PDF_LOGO } from '../../../../common/constants';
import { ConditionalHeaders } from '../../../types';
import { JobDocPayloadPDF } from '../../printable_pdf/types'; // Logo is PDF only
import { ScheduledTaskParamsPDF } from '../../printable_pdf/types'; // Logo is PDF only

export const getCustomLogo = async ({
reporting,
Expand All @@ -17,7 +17,7 @@ export const getCustomLogo = async ({
}: {
reporting: ReportingCore;
config: ReportingConfig;
job: JobDocPayloadPDF;
job: ScheduledTaskParamsPDF;
conditionalHeaders: ConditionalHeaders;
}) => {
const serverBasePath: string = config.kbnConfig.get('server', 'basePath');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/

import { ReportingConfig } from '../../../';
import { JobDocPayloadPNG } from '../../png/types';
import { JobDocPayloadPDF } from '../../printable_pdf/types';
import { ScheduledTaskParamsPNG } from '../../png/types';
import { ScheduledTaskParamsPDF } from '../../printable_pdf/types';
import { getFullUrls } from './get_full_urls';

interface FullUrlsOpts {
job: JobDocPayloadPNG & JobDocPayloadPDF;
job: ScheduledTaskParamsPNG & ScheduledTaskParamsPDF;
config: ReportingConfig;
}

Expand All @@ -35,7 +35,7 @@ beforeEach(() => {
mockConfig = getMockConfig(mockConfigGet);
});

const getMockJob = (base: object) => base as JobDocPayloadPNG & JobDocPayloadPDF;
const getMockJob = (base: object) => base as ScheduledTaskParamsPNG & ScheduledTaskParamsPDF;

test(`fails if no URL is passed`, async () => {
const fn = () => getFullUrls({ job: getMockJob({}), config: mockConfig } as FullUrlsOpts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,26 @@ import {
import { ReportingConfig } from '../../..';
import { getAbsoluteUrlFactory } from '../../../../common/get_absolute_url';
import { validateUrls } from '../../../../common/validate_urls';
import { JobDocPayloadPNG } from '../../png/types';
import { JobDocPayloadPDF } from '../../printable_pdf/types';
import { ScheduledTaskParamsPNG } from '../../png/types';
import { ScheduledTaskParamsPDF } from '../../printable_pdf/types';

function isPngJob(job: JobDocPayloadPNG | JobDocPayloadPDF): job is JobDocPayloadPNG {
return (job as JobDocPayloadPNG).relativeUrl !== undefined;
function isPngJob(
job: ScheduledTaskParamsPNG | ScheduledTaskParamsPDF
): job is ScheduledTaskParamsPNG {
return (job as ScheduledTaskParamsPNG).relativeUrl !== undefined;
}
function isPdfJob(job: JobDocPayloadPNG | JobDocPayloadPDF): job is JobDocPayloadPDF {
return (job as JobDocPayloadPDF).relativeUrls !== undefined;
function isPdfJob(
job: ScheduledTaskParamsPNG | ScheduledTaskParamsPDF
): job is ScheduledTaskParamsPDF {
return (job as ScheduledTaskParamsPDF).relativeUrls !== undefined;
}

export function getFullUrls<JobDocPayloadType>({
export function getFullUrls<ScheduledTaskParamsType>({
config,
job,
}: {
config: ReportingConfig;
job: JobDocPayloadPDF | JobDocPayloadPNG;
job: ScheduledTaskParamsPDF | ScheduledTaskParamsPNG;
}) {
const [basePath, protocol, hostname, port] = [
config.kbnConfig.get('server', 'basePath'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
KBN_SCREENSHOT_HEADER_BLACKLIST_STARTS_WITH_PATTERN,
} from '../../../../common/constants';

export const omitBlacklistedHeaders = <JobDocPayloadType>({
export const omitBlacklistedHeaders = <ScheduledTaskParamsType>({
job,
decryptedHeaders,
}: {
job: JobDocPayloadType;
job: ScheduledTaskParamsType;
decryptedHeaders: Record<string, string>;
}) => {
const filteredHeaders: Record<string, string> = omit(
Expand Down
14 changes: 7 additions & 7 deletions x-pack/plugins/reporting/server/export_types/csv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ import {
import { CSV_JOB_TYPE as jobType } from '../../../constants';
import { ESQueueCreateJobFn, ESQueueWorkerExecuteFn, ExportTypeDefinition } from '../../types';
import { metadata } from './metadata';
import { createJobFactory } from './server/create_job';
import { executeJobFactory } from './server/execute_job';
import { JobDocPayloadDiscoverCsv, JobParamsDiscoverCsv } from './types';
import { scheduleTaskFnFactory } from './server/create_job';
import { runTaskFnFactory } from './server/execute_job';
import { JobParamsDiscoverCsv, ScheduledTaskParamsCSV } from './types';

export const getExportType = (): ExportTypeDefinition<
JobParamsDiscoverCsv,
ESQueueCreateJobFn<JobParamsDiscoverCsv>,
JobDocPayloadDiscoverCsv,
ESQueueWorkerExecuteFn<JobDocPayloadDiscoverCsv>
ScheduledTaskParamsCSV,
ESQueueWorkerExecuteFn<ScheduledTaskParamsCSV>
> => ({
...metadata,
jobType,
jobContentExtension: 'csv',
createJobFactory,
executeJobFactory,
scheduleTaskFnFactory,
runTaskFnFactory,
validLicenses: [
LICENSE_TYPE_TRIAL,
LICENSE_TYPE_BASIC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { KibanaRequest, RequestHandlerContext } from 'src/core/server';
import { ReportingCore } from '../../../';
import { cryptoFactory } from '../../../lib';
import { CreateJobFactory, ESQueueCreateJobFn } from '../../../types';
import { ESQueueCreateJobFn, ScheduleTaskFnFactory } from '../../../types';
import { JobParamsDiscoverCsv } from '../types';

export const createJobFactory: CreateJobFactory<ESQueueCreateJobFn<
export const scheduleTaskFnFactory: ScheduleTaskFnFactory<ESQueueCreateJobFn<
JobParamsDiscoverCsv
>> = function createJobFactoryFn(reporting: ReportingCore) {
>> = function createJobFactoryFn(reporting) {
const config = reporting.getConfig();
const crypto = cryptoFactory(config.get('encryptionKey'));
const setupDeps = reporting.getPluginSetupDeps();

return async function createJob(
jobParams: JobParamsDiscoverCsv,
context: RequestHandlerContext,
request: KibanaRequest
) {
return async function scheduleTask(jobParams, context, request) {
const serializedEncryptedHeaders = await crypto.encrypt(request.headers);

const savedObjectsClient = context.core.savedObjects.client;
Expand Down
Loading
Loading