-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,992 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
x-pack/plugins/reporting/common/types/export_types/csv_v2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { BaseParamsV2, BasePayloadV2 } from '../base'; | ||
|
||
interface CsvFromSavedObjectBase { | ||
objectType: 'search'; | ||
} | ||
|
||
/** | ||
* Makes title optional, as it can be derived from the saved search object | ||
*/ | ||
export type JobParamsCsvFromSavedObject = CsvFromSavedObjectBase & | ||
Omit<BaseParamsV2, 'title'> & { title?: string }; | ||
|
||
/** | ||
* | ||
*/ | ||
export type TaskPayloadCsvFromSavedObject = CsvFromSavedObjectBase & BasePayloadV2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
], | ||
"requiredPlugins": [ | ||
"data", | ||
"discover", | ||
"fieldFormats", | ||
"esUiShared", | ||
"home", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
x-pack/plugins/reporting/server/export_types/csv_v2/create_job.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import Boom from '@hapi/boom'; | ||
import { JobParamsCsvFromSavedObject, TaskPayloadCsvFromSavedObject } from '../../../common/types'; | ||
import { CreateJobFn, CreateJobFnFactory } from '../../types'; | ||
|
||
type CreateJobFnType = CreateJobFn<JobParamsCsvFromSavedObject, TaskPayloadCsvFromSavedObject>; | ||
|
||
export const createJobFnFactory: CreateJobFnFactory<CreateJobFnType> = function createJobFactoryFn( | ||
reporting | ||
) { | ||
return async function createJob(jobParams, _context, req) { | ||
// 1. Validation of locatorParams | ||
const { locatorParams } = jobParams; | ||
const { id, params } = locatorParams[0]; | ||
if ( | ||
!locatorParams || | ||
!Array.isArray(locatorParams) || | ||
locatorParams.length !== 1 || | ||
id !== 'DISCOVER_APP_LOCATOR' || | ||
!params | ||
) { | ||
throw Boom.badRequest('Invalid Job params: must contain a single Discover App locator'); | ||
} | ||
|
||
if (!params || !params.savedSearchId || typeof params.savedSearchId !== 'string') { | ||
throw Boom.badRequest('Invalid Discover App locator: must contain a savedSearchId'); | ||
} | ||
|
||
// use Discover contract to get the title of the report from job params | ||
const { discover: discoverPluginStart } = await reporting.getPluginStartDeps(); | ||
const locatorClient = await discoverPluginStart.locator.asScopedClient(req); | ||
const title = await locatorClient.titleFromLocator(params); | ||
|
||
return { ...jobParams, title }; | ||
}; | ||
}; |
63 changes: 63 additions & 0 deletions
63
x-pack/plugins/reporting/server/export_types/csv_v2/execute_job.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { TaskPayloadCsvFromSavedObject } from '../../../common/types'; | ||
import { getFieldFormats } from '../../services'; | ||
import type { RunTaskFn, RunTaskFnFactory } from '../../types'; | ||
import { decryptJobHeaders } from '../common'; | ||
import { CsvGenerator } from '../csv_searchsource/generate_csv'; | ||
|
||
type RunTaskFnType = RunTaskFn<TaskPayloadCsvFromSavedObject>; | ||
|
||
export const runTaskFnFactory: RunTaskFnFactory<RunTaskFnType> = (reporting, _logger) => { | ||
const config = reporting.getConfig(); | ||
const encryptionKey = config.get('encryptionKey'); | ||
const csvConfig = config.get('csv'); | ||
|
||
return async function runTask(jobId, job, cancellationToken, stream) { | ||
const logger = _logger.get(`execute:${jobId}`); | ||
|
||
const headers = await decryptJobHeaders(encryptionKey, job.headers, logger); | ||
const fakeRequest = reporting.getFakeRequest(headers, job.spaceId, logger); | ||
const uiSettings = await reporting.getUiSettingsClient(fakeRequest, logger); | ||
const fieldFormatsRegistry = await getFieldFormats().fieldFormatServiceFactory(uiSettings); | ||
const { data: dataPluginStart, discover: discoverPluginStart } = | ||
await reporting.getPluginStartDeps(); | ||
const data = dataPluginStart.search.asScoped(fakeRequest); | ||
|
||
const { locatorParams } = job; | ||
const { params } = locatorParams[0]; | ||
|
||
// use Discover contract to convert the job params into inputs for CsvGenerator | ||
const locatorClient = await discoverPluginStart.locator.asScopedClient(fakeRequest); | ||
const columns = await locatorClient.columnsFromLocator(params); | ||
const searchSource = await locatorClient.searchSourceFromLocator(params); | ||
|
||
const [es, searchSourceStart] = await Promise.all([ | ||
(await reporting.getEsClient()).asScoped(fakeRequest), | ||
await dataPluginStart.search.searchSource.asScoped(fakeRequest), | ||
]); | ||
|
||
const clients = { uiSettings, data, es }; | ||
const dependencies = { searchSourceStart, fieldFormatsRegistry }; | ||
|
||
const csv = new CsvGenerator( | ||
{ | ||
columns, | ||
searchSource: searchSource.getSerializedFields(true), | ||
...job, | ||
}, | ||
csvConfig, | ||
clients, | ||
dependencies, | ||
cancellationToken, | ||
logger, | ||
stream | ||
); | ||
return await csv.generateData(); | ||
}; | ||
}; |
40 changes: 40 additions & 0 deletions
40
x-pack/plugins/reporting/server/export_types/csv_v2/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
CSV_REPORT_TYPE_V2 as CSV_JOB_TYPE, | ||
LICENSE_TYPE_BASIC, | ||
LICENSE_TYPE_CLOUD_STANDARD, | ||
LICENSE_TYPE_ENTERPRISE, | ||
LICENSE_TYPE_GOLD, | ||
LICENSE_TYPE_PLATINUM, | ||
LICENSE_TYPE_TRIAL, | ||
} from '../../../common/constants'; | ||
import { JobParamsCsvFromSavedObject, TaskPayloadCsvFromSavedObject } from '../../../common/types'; | ||
import { CreateJobFn, ExportTypeDefinition, RunTaskFn } from '../../types'; | ||
import { createJobFnFactory } from './create_job'; | ||
import { runTaskFnFactory } from './execute_job'; | ||
|
||
export const getExportType = (): ExportTypeDefinition< | ||
CreateJobFn<JobParamsCsvFromSavedObject>, | ||
RunTaskFn<TaskPayloadCsvFromSavedObject> | ||
> => ({ | ||
id: CSV_JOB_TYPE, | ||
name: CSV_JOB_TYPE, | ||
jobType: CSV_JOB_TYPE, | ||
jobContentExtension: 'csv', | ||
createJobFnFactory, | ||
runTaskFnFactory, | ||
validLicenses: [ | ||
LICENSE_TYPE_TRIAL, | ||
LICENSE_TYPE_BASIC, | ||
LICENSE_TYPE_CLOUD_STANDARD, | ||
LICENSE_TYPE_GOLD, | ||
LICENSE_TYPE_PLATINUM, | ||
LICENSE_TYPE_ENTERPRISE, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.