Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Jul 13, 2020
1 parent 15b21a1 commit a2cecc4
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export const csvReportingProvider = ({
disabled = !enableLinks;
});

// If the TZ is set to the default "Browser", it will not be useful for
// server-side export. We need to derive the timezone and pass it as a param
// to the export API.
const browserTimezone =
uiSettings.get('dateFormat:tz') === 'Browser'
? moment.tz.guess()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export const reportingPDFPNGProvider = ({
disabled = !enableLinks;
});

// If the TZ is set to the default "Browser", it will not be useful for
// server-side export. We need to derive the timezone and pass it as a param
// to the export API.
const browserTimezone =
uiSettings.get('dateFormat:tz') === 'Browser'
? moment.tz.guess()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,55 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Crypto } from '@elastic/node-crypto';
import { i18n } from '@kbn/i18n';
import Hapi from 'hapi';
import { KibanaRequest } from '../../../../../../../src/core/server';
import { CONTENT_TYPE_CSV, CSV_JOB_TYPE } from '../../../../common/constants';
import { cryptoFactory } from '../../../lib';
import { cryptoFactory, LevelLogger } from '../../../lib';
import { ESQueueWorkerExecuteFn, RunTaskFnFactory } from '../../../types';
import { ScheduledTaskParamsCSV } from '../types';
import { createGenerateCsv } from './generate_csv';
import { getRequest } from './lib/get_request';

const getRequest = async (headers: string | undefined, crypto: Crypto, logger: LevelLogger) => {
const decryptHeaders = async () => {
try {
if (typeof headers !== 'string') {
throw new Error(
i18n.translate(
'xpack.reporting.exportTypes.csv.executeJob.missingJobHeadersErrorMessage',
{
defaultMessage: 'Job headers are missing',
}
)
);
}
return await crypto.decrypt(headers);
} catch (err) {
logger.error(err);
throw new Error(
i18n.translate(
'xpack.reporting.exportTypes.csv.executeJob.failedToDecryptReportJobDataErrorMessage',
{
defaultMessage: 'Failed to decrypt report job data. Please ensure that {encryptionKey} is set and re-generate this report. {err}',
values: { encryptionKey: 'xpack.reporting.encryptionKey', err: err.toString() },
}
)
); // prettier-ignore
}
};

return KibanaRequest.from({
headers: await decryptHeaders(),
// This is used by the spaces SavedObjectClientWrapper to determine the existing space.
// We use the basePath from the saved job, which we'll have post spaces being implemented;
// or we use the server base path, which uses the default space
path: '/',
route: { settings: {} },
url: { href: '/' },
raw: { req: { url: '/' } },
} as Hapi.Request);
};

export const runTaskFnFactory: RunTaskFnFactory<ESQueueWorkerExecuteFn<
ScheduledTaskParamsCSV
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import Hapi from 'hapi';
import { KibanaRequest } from '../../../../../../../../src/core/server';
import { LevelLogger } from '../../../../lib';

/*
* FIXME: remove this function. CSV From Saved Object export is only
* synchronous - only needs to deal with a real request object */
export const getRequest = async (
headers: string | undefined,
crypto: Crypto,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export interface ScheduledTaskParamsCSV extends ScheduledTaskParams<JobParamsDis
conflictedTypesFields: any;
}

// FIXME should be provided by serverside data access plugin
export interface SearchRequest {
index: string;
body:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const getGenerateCsvParams = async (
docvalue_fields: docValueFields,
query: esQuery.buildEsQuery(
indexPatternSavedObject as IIndexPattern,
(searchSourceQuery as unknown) as Query, // FIXME use the types from data plugin
(searchSourceQuery as unknown) as Query,
(combinedFilter as unknown) as Filter,
esQueryConfig
),
Expand Down

0 comments on commit a2cecc4

Please sign in to comment.