-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] Convert Export Type Definitions to Typescript #51643
Changes from all commits
5531c06
d409bf0
87fb7a0
4d8f03e
74caad1
c4aff15
dea6767
9729aea
0ac0879
e5b9fd4
aabd4da
08dbaa0
1fb9462
1db2b7e
9ffff82
1d300b1
c173316
cd22792
32bf3fd
7267351
86a8711
e18cb07
0107d9d
e4eaa02
52b9741
00870d6
f69b5b3
55f7071
df29171
9ca9f79
81f54a8
2bc9907
6172995
5ce0bb7
4048408
ab9fe91
171f7ed
60fbee9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,48 @@ | |
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
// @ts-ignore | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { cryptoFactory } from '../../../server/lib/crypto'; | ||
import { CryptoFactory, JobDocPayload, ServerFacade } from '../../../types'; | ||
import { CryptoFactory, ServerFacade, Logger } from '../../../types'; | ||
|
||
interface HasEncryptedHeaders { | ||
headers?: string; | ||
} | ||
|
||
export const decryptJobHeaders = async ({ | ||
// TODO merge functionality with CSV execute job | ||
export const decryptJobHeaders = async < | ||
JobParamsType, | ||
JobDocPayloadType extends HasEncryptedHeaders | ||
>({ | ||
job, | ||
server, | ||
logger, | ||
}: { | ||
job: JobDocPayload; | ||
job: JobDocPayloadType; | ||
server: ServerFacade; | ||
}) => { | ||
logger: Logger; | ||
}): Promise<{ | ||
job: JobDocPayloadType; | ||
server: ServerFacade; | ||
decryptedHeaders: Record<string, string>; | ||
}> => { | ||
const crypto: CryptoFactory = cryptoFactory(server); | ||
const decryptedHeaders: string = await crypto.decrypt(job.headers); | ||
return { job, decryptedHeaders, server }; | ||
try { | ||
const decryptedHeaders: Record<string, string> = await crypto.decrypt(job.headers); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realise this isn't new in this code, but is this path on an api that's open to the world? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The execute job functions are only called in the server background, when a reporting job is claimed. Then the job parameters, which include encrypted headers, get passed to the execute job function. This is a great consideration though which hasn't come up before. I know we'd really like to move away from encrypting the header from the generation request and use some kind of token for authentication, but how/when we'll do that isn't yet clear. |
||
return { job, decryptedHeaders, server }; | ||
} catch (err) { | ||
logger.error(err); | ||
tsullivan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
throw new Error( | ||
i18n.translate( | ||
'xpack.reporting.exportTypes.common.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() }, | ||
} | ||
) | ||
); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looked weird to me that this isn't in a
describe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is an anti-pattern from what I recall.