From 0a869dc1f71dcedd9871743fb4e718cf6ed40cb4 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 29 Sep 2020 23:30:24 +0100 Subject: [PATCH] chore(NA): update code to run under last extract-zip version --- .../server/browsers/extract/unzip.js | 16 +++----- .../scripts/beat_docs/build.js | 38 +++++++++---------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/x-pack/plugins/reporting/server/browsers/extract/unzip.js b/x-pack/plugins/reporting/server/browsers/extract/unzip.js index d57d04a52f46e..d5166f149372a 100644 --- a/x-pack/plugins/reporting/server/browsers/extract/unzip.js +++ b/x-pack/plugins/reporting/server/browsers/extract/unzip.js @@ -7,14 +7,10 @@ import extractZip from 'extract-zip'; import { ExtractError } from './extract_error'; -export function unzip(filepath, target) { - return new Promise(function (resolve, reject) { - extractZip(filepath, { dir: target }, (err) => { - if (err) { - return reject(new ExtractError(err)); - } - - resolve(); - }); - }); +export async function unzip(filepath, target) { + try { + await extractZip(filepath, { dir: target }); + } catch (err) { + throw new ExtractError(err); + } } diff --git a/x-pack/plugins/security_solution/scripts/beat_docs/build.js b/x-pack/plugins/security_solution/scripts/beat_docs/build.js index 9b3607593a5db..3dbfb75fbe32e 100644 --- a/x-pack/plugins/security_solution/scripts/beat_docs/build.js +++ b/x-pack/plugins/security_solution/scripts/beat_docs/build.js @@ -135,25 +135,25 @@ const convertSchemaToHash = (schema, beatFields) => { }, beatFields); }; -const manageZipFields = async (beat, filePath, beatFields) => - new Promise((resolve, reject) => { - extract(filePath, { dir: beat.outputDir }, (err) => { - if (err) { - return reject(new Error(err)); - } - console.log('building fields', beat.index); - const obj = yaml.load( - fs.readFileSync(`${beat.outputDir}/winlogbeat-7.9.0-windows-x86_64/fields.yml`, { - encoding: 'utf-8', - }) - ); - const eBeatFields = convertSchemaToHash(obj, beatFields); - console.log('deleting files', beat.index); - rimraf.sync(`${beat.outputDir}/winlogbeat-7.9.0-windows-x86_64`); - rimraf.sync(beat.filePath); - resolve(eBeatFields); - }); - }); +const manageZipFields = async (beat, filePath, beatFields) => { + try { + await extract(filePath, { dir: beat.outputDir }); + console.log('building fields', beat.index); + const obj = yaml.load( + fs.readFileSync(`${beat.outputDir}/winlogbeat-7.9.0-windows-x86_64/fields.yml`, { + encoding: 'utf-8', + }) + ); + const eBeatFields = convertSchemaToHash(obj, beatFields); + console.log('deleting files', beat.index); + rimraf.sync(`${beat.outputDir}/winlogbeat-7.9.0-windows-x86_64`); + rimraf.sync(beat.filePath); + + return eBeatFields; + } catch (err) { + throw new Error(err); + } +}; const manageTarFields = async (beat, filePath, beatFields) => new Promise((resolve, reject) => {