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 interfaces to align with task manager integration #76716

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 1 addition & 2 deletions x-pack/plugins/reporting/server/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ import {
} from 'src/core/server';
import { LicensingPluginSetup } from '../../licensing/server';
import { SecurityPluginSetup } from '../../security/server';
import { ScreenshotsObservableFn } from '../server/types';
import { ReportingConfig } from './';
import { HeadlessChromiumDriverFactory } from './browsers/chromium/driver_factory';
import { screenshotsObservableFactory } from './lib/screenshots';
import { checkLicense, getExportTypesRegistry } from './lib';
import { ESQueueInstance } from './lib/create_queue';
import { screenshotsObservableFactory, ScreenshotsObservableFn } from './lib/screenshots';
import { ReportingStore } from './lib/store';

export interface ReportingInternalSetup {
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,
ScheduledTaskParamsType extends HasEncryptedHeaders
TaskPayloadType extends HasEncryptedHeaders
>({
encryptionKey,
job,
logger,
}: {
encryptionKey?: string;
job: ScheduledTaskParamsType;
job: TaskPayloadType;
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 { ScheduledTaskParams } from '../../types';
import { ScheduledTaskParamsPDF } from '../printable_pdf/types';
import { BasePayload } from '../../types';
import { TaskPayloadPDF } from '../printable_pdf/types';
import { getConditionalHeaders, getCustomLogo } from './';

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

const conditionalHeaders = await getConditionalHeaders({
job: {} as ScheduledTaskParams<any>,
job: {} as BasePayload<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 ScheduledTaskParams<any>,
job: {} as BasePayload<any>,
filteredHeaders: permittedHeaders,
config: mockConfig,
});
const jobBasePath = '/sbp/s/marketing';
await getCustomLogo({
reporting: mockReportingPlugin,
job: { basePath: jobBasePath } as ScheduledTaskParamsPDF,
job: { basePath: jobBasePath } as TaskPayloadPDF,
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 ScheduledTaskParams<any>,
job: {} as BasePayload<any>,
filteredHeaders: permittedHeaders,
config: mockConfig,
});

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

const conditionalHeaders = await getConditionalHeaders({
job: {} as ScheduledTaskParams<any>,
job: {} as BasePayload<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 = <ScheduledTaskParamsType>({
export const getConditionalHeaders = <TaskPayloadType>({
config,
job,
filteredHeaders,
}: {
config: ReportingConfig;
job: ScheduledTaskParamsType;
job: TaskPayloadType;
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 { ScheduledTaskParamsPDF } from '../printable_pdf/types';
import { TaskPayloadPDF } from '../printable_pdf/types';
import { getConditionalHeaders, getCustomLogo } from './';

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 ScheduledTaskParamsPDF,
job: {} as TaskPayloadPDF,
filteredHeaders: permittedHeaders,
config: mockConfig,
});

const { logo } = await getCustomLogo({
reporting: mockReportingPlugin,
config: mockConfig,
job: {} as ScheduledTaskParamsPDF,
job: {} as TaskPayloadPDF,
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 { ScheduledTaskParamsPDF } from '../printable_pdf/types'; // Logo is PDF only
import { TaskPayloadPDF } 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: ScheduledTaskParamsPDF;
job: TaskPayloadPDF;
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 { ScheduledTaskParamsPNG } from '../png/types';
import { ScheduledTaskParamsPDF } from '../printable_pdf/types';
import { TaskPayloadPNG } from '../png/types';
import { TaskPayloadPDF } from '../printable_pdf/types';
import { getFullUrls } from './get_full_urls';

interface FullUrlsOpts {
job: ScheduledTaskParamsPNG & ScheduledTaskParamsPDF;
job: TaskPayloadPNG & TaskPayloadPDF;
config: ReportingConfig;
}

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

const getMockJob = (base: object) => base as ScheduledTaskParamsPNG & ScheduledTaskParamsPDF;
const getMockJob = (base: object) => base as TaskPayloadPNG & TaskPayloadPDF;

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 @@ -11,28 +11,24 @@ import {
UrlWithStringQuery,
} from 'url';
import { ReportingConfig } from '../../';
import { ScheduledTaskParamsPNG } from '../png/types';
import { ScheduledTaskParamsPDF } from '../printable_pdf/types';
import { TaskPayloadPNG } from '../png/types';
import { TaskPayloadPDF } from '../printable_pdf/types';
import { getAbsoluteUrlFactory } from './get_absolute_url';
import { validateUrls } from './validate_urls';

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

export function getFullUrls<ScheduledTaskParamsType>({
export function getFullUrls<TaskPayloadType>({
config,
job,
}: {
config: ReportingConfig;
job: ScheduledTaskParamsPDF | ScheduledTaskParamsPNG;
job: TaskPayloadPDF | TaskPayloadPNG;
}) {
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 = <ScheduledTaskParamsType>({
export const omitBlacklistedHeaders = <TaskPayloadType>({
job,
decryptedHeaders,
}: {
job: ScheduledTaskParamsType;
job: TaskPayloadType;
decryptedHeaders: Record<string, string>;
}) => {
const filteredHeaders: Record<string, string> = omitBy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
*/

import { cryptoFactory } from '../../lib';
import { CreateJobFn, ScheduleTaskFnFactory } from '../../types';
import { CreateJobFn, CreateJobFnFactory } from '../../types';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about keeping the task nomenclature here? CreateTaskFnFactory?

import { JobParamsDiscoverCsv } from './types';

export const scheduleTaskFnFactory: ScheduleTaskFnFactory<CreateJobFn<
export const createJobFnFactory: CreateJobFnFactory<CreateJobFn<
JobParamsDiscoverCsv
>> = function createJobFactoryFn(reporting) {
const config = reporting.getConfig();
const crypto = cryptoFactory(config.get('encryptionKey'));

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

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