Skip to content

Commit

Permalink
[Reporting/fix] include the error object job decryption errors (#32216)
Browse files Browse the repository at this point in the history
* [Reporting/fix] include the error object in the messages about can't decrypt the job data

+ Prettier fixes

* fix translation string values

* fix i18n

* fix translation files
  • Loading branch information
tsullivan authored Mar 11, 2019
1 parent 671269e commit 4088c9c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 22 deletions.
10 changes: 6 additions & 4 deletions x-pack/plugins/reporting/export_types/csv/server/execute_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ function executeJobFn(server) {
let decryptedHeaders;
try {
decryptedHeaders = await crypto.decrypt(serializedEncryptedHeaders);
} catch (e) {
} catch (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.',
values: { encryptionKey: 'xpack.reporting.encryptionKey' },
'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() },
}
)
);
Expand Down Expand Up @@ -79,7 +79,9 @@ function executeJobFn(server) {
]);

if (timezone === 'Browser') {
logger.warn(`Kibana Advanced Setting "dateFormat:tz" is set to "Browser". Dates will be formatted as UTC to avoid ambiguity.`);
logger.warn(
`Kibana Advanced Setting "dateFormat:tz" is set to "Browser". Dates will be formatted as UTC to avoid ambiguity.`
);
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,35 @@
*/

import * as Rx from 'rxjs';
import { i18n } from '@kbn/i18n';
import { mergeMap, catchError, map, takeUntil } from 'rxjs/operators';
import { oncePerServer } from '../../../../server/lib/once_per_server';
import { generatePngObservableFactory } from '../lib/generate_png';
import { decryptJobHeaders, omitBlacklistedHeaders, getConditionalHeaders, addForceNowQuerystring } from '../../../common/execute_job/';
import {
decryptJobHeaders,
omitBlacklistedHeaders,
getConditionalHeaders,
addForceNowQuerystring,
} from '../../../common/execute_job/';

function executeJobFn(server) {
const generatePngObservable = generatePngObservableFactory(server);

return function executeJob(jobToExecute, cancellationToken) {
const process$ = Rx.of({ job: jobToExecute, server }).pipe(
mergeMap(decryptJobHeaders),
catchError(() => Rx.throwError('Failed to decrypt report job data. Please re-generate this report.')),
catchError(err =>
Rx.throwError(
i18n.translate(
'xpack.reporting.exportTypes.png.compShim.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() },
}
)
)
),
map(omitBlacklistedHeaders),
map(getConditionalHeaders),
mergeMap(addForceNowQuerystring),
Expand All @@ -33,9 +50,7 @@ function executeJobFn(server) {

const stop$ = Rx.fromEventPattern(cancellationToken.on);

return process$.pipe(
takeUntil(stop$)
).toPromise();
return process$.pipe(takeUntil(stop$)).toPromise();
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import { i18n } from '@kbn/i18n';
import { oncePerServer } from '../../../../server/lib/once_per_server';
import { generatePdfObservableFactory } from '../lib/generate_pdf';
import { compatibilityShimFactory } from './compatibility_shim';
import { decryptJobHeaders, omitBlacklistedHeaders, getConditionalHeaders,
addForceNowQuerystring, getCustomLogo } from '../../../common/execute_job/';

import {
decryptJobHeaders,
omitBlacklistedHeaders,
getConditionalHeaders,
addForceNowQuerystring,
getCustomLogo,
} from '../../../common/execute_job/';

function executeJobFn(server) {
const generatePdfObservable = generatePdfObservableFactory(server);
Expand All @@ -21,16 +25,31 @@ function executeJobFn(server) {
return compatibilityShim(function executeJob(jobToExecute, cancellationToken) {
const process$ = Rx.of({ job: jobToExecute, server }).pipe(
mergeMap(decryptJobHeaders),
catchError(() => Rx.throwError(
i18n.translate('xpack.reporting.exportTypes.printablePdf.compShim.failedToDecryptReportJobDataErrorMessage', {
defaultMessage: 'Failed to decrypt report job data. Please re-generate this report.'
}))),
catchError(err =>
Rx.throwError(
i18n.translate(
'xpack.reporting.exportTypes.printablePdf.compShim.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() },
}
)
)
),
map(omitBlacklistedHeaders),
map(getConditionalHeaders),
mergeMap(getCustomLogo),
mergeMap(addForceNowQuerystring),
mergeMap(({ job, conditionalHeaders, logo, urls }) => {
return generatePdfObservable(job.title, urls, job.browserTimezone, conditionalHeaders, job.layout, logo);
return generatePdfObservable(
job.title,
urls,
job.browserTimezone,
conditionalHeaders,
job.layout,
logo
);
}),
map(buffer => ({
content_type: 'application/pdf',
Expand All @@ -41,9 +60,7 @@ function executeJobFn(server) {

const stop$ = Rx.fromEventPattern(cancellationToken.on);

return process$.pipe(
takeUntil(stop$)
).toPromise();
return process$.pipe(takeUntil(stop$)).toPromise();
});
}

Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -7169,10 +7169,8 @@
"xpack.reporting.errorButton.showReportErrorAriaLabel": "显示报告错误",
"xpack.reporting.errorButton.unableToFetchReportContentTitle": "无法提取报告内容",
"xpack.reporting.errorButton.unableToGenerateReportTitle": "无法生成报告",
"xpack.reporting.exportTypes.csv.executeJob.failedToDecryptReportJobDataErrorMessage": "无法解密报告作业数据。请确保已设置 {encryptionKey},然后重新生成此报告。",
"xpack.reporting.exportTypes.csv.hitIterator.expectedHitsErrorMessage": "在以下 Elasticsearch 响应中预期 {hits}:{response}",
"xpack.reporting.exportTypes.csv.hitIterator.expectedScrollIdErrorMessage": "在以下 Elasticsearch 响应中预期 {scrollId}:{response}",
"xpack.reporting.exportTypes.printablePdf.compShim.failedToDecryptReportJobDataErrorMessage": "无法解密报告作业数据。请重新生成此报告。",
"xpack.reporting.exportTypes.printablePdf.compShim.unableToGenerateReportErrorMessage": "无法为 url {savedObjUrl} 生成报告,它不是 Kibana URL",
"xpack.reporting.exportTypes.printablePdf.documentStreamIsNotgeneratedErrorMessage": "尚未生成文档流",
"xpack.reporting.exportTypes.printablePdf.logoDescription": "由 Elastic 提供支持",
Expand Down

0 comments on commit 4088c9c

Please sign in to comment.