Skip to content
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

Swapped adm-zip out for zip.js #6018

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@vue/cli-service": "^5.0.8",
"@vue/eslint-config-prettier": "^7.0.0",
"@vue/eslint-config-typescript": "^13.0.0",
"adm-zip": "^0.5.10",
"@zip.js/zip.js": "^2.7.47",
"apexcharts": "^3.10.1",
"axios": "^1.3.5",
"chroma-js": "^2.1.0",
Expand Down Expand Up @@ -113,7 +113,6 @@
"xml-js": "^1.6.11"
},
"devDependencies": {
"@types/adm-zip": "^0.5.0",
"@types/chai": "^4.2.5",
"@types/chai-as-promised": "^7.1.2",
"@types/jest": "^27.0.0",
Expand All @@ -133,7 +132,7 @@
"prismjs": "1.29.0"
},
"engines": {
"node": "^18.19.0"
"node": ">=18.19.0"
},
"branch": "/blob/master/",
"changelog": "/releases",
Expand Down
1 change: 0 additions & 1 deletion apps/frontend/src/types/adm-zip/index.d.ts

This file was deleted.

24 changes: 16 additions & 8 deletions apps/frontend/src/utilities/export_util.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import ZipFile from 'adm-zip';
import {saveAs} from 'file-saver';
let zip: any;
try {
(async () => {
zip = await import('@zip.js/zip.js');
})();
} catch (e) {
console.log(`zip module import failed: ${e}`);
}

type File = {
filename: string;
data: string;
};

export async function saveSingleOrMultipleFiles(
files: File[],
filetype: string
Expand All @@ -13,13 +21,13 @@ export async function saveSingleOrMultipleFiles(
const blob = new Blob([files[0].data]);
saveAs(blob, cleanUpFilename(`${files[0]?.filename}`));
} else {
const zipfile = new ZipFile();
files.forEach((file) => {
const buffer = Buffer.from(file.data);
zipfile.addFile(file.filename, buffer);
});
const blob = new Blob([zipfile.toBuffer()]);
saveAs(blob, `exported_${filetype}s.zip`);
const zipWriter = new zip.ZipWriter(new zip.BlobWriter());
await Promise.all(
files.map((file) =>
zipWriter.add(file.filename, new zip.TextReader(file.data))
)
);
saveAs(await zipWriter.close(), `exported_${filetype}s.zip`);
}
}

Expand Down
44 changes: 23 additions & 21 deletions apps/frontend/src/utilities/tenable_util.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import Zip from 'adm-zip';
import axios, {AxiosInstance} from 'axios';
import {ServerModule} from '@/store/server';
import {createWinstonLogger} from '../../../../libs/hdf-converters/src/utils/global';

let zip: any;
try {
(async () => {
zip = await import('@zip.js/zip.js');
})();
} catch (e) {
console.log(`zip module import failed: ${e}`);
}

/** represents the information of the current used */
export interface AuthInfo {
accesskey: string;
Expand Down Expand Up @@ -45,7 +53,7 @@ export class TenableUtil {

async loginToTenable(): Promise<boolean> {
logger.info(`Connecting to Tenable Client`);
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
setTimeout(
() =>
reject(
Expand All @@ -57,7 +65,7 @@ export class TenableUtil {
);

try {
this.axios_instance({
const response = await this.axios_instance({
method: 'get',
url: '/rest/currentUser'
})
Expand Down Expand Up @@ -137,7 +145,7 @@ export class TenableUtil {
*/
async getScans(startTime: number, endTime: number): Promise<[]> {
logger.info(`Getting scans from Tenable Client`);
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
setTimeout(
() =>
reject(
Expand All @@ -149,7 +157,7 @@ export class TenableUtil {
);

try {
this.axios_instance({
const response = await this.axios_instance({
method: 'get',
url: `/rest/scanResult?fields=name,description,details,scannedIPs,totalChecks,startTime,finishTime,status&startTime=${startTime}&endTime=${endTime}`
})
Expand All @@ -175,7 +183,7 @@ export class TenableUtil {
*/
async getVulnerabilities(scanId: string): Promise<string> {
logger.info(`Getting vulnerabilities from Tenable Client`);
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
setTimeout(
() =>
reject(
Expand All @@ -187,24 +195,18 @@ export class TenableUtil {
);

try {
this.axios_instance({
const response = await this.axios_instance({
method: 'post',
url: `rest/scanResult/${scanId}/download?downloadType=v2`,
responseType: 'arraybuffer'
})
.then((response) => {
// Unzip response in memory
try {
const zip = new Zip(Buffer.from(response.data));
const zipEntries = zip.getEntries();
resolve(zip.readAsText(zipEntries[0]));
} catch (unzipErr) {
reject(unzipErr);
}
})
.catch((error) => {
reject(error);
});
});
const zipReader = new zip.ZipReader(
new zip.BlobReader(Buffer.from(response.data))
);
const zipEntries = await zipReader.getEntries();
const contents = await zipEntries[0].getData(new zip.TextWriter());
await zipReader.close();
resolve(contents);
} catch (e) {
reject(e);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"dotenv-cli": "^7.0.0"
},
"engines": {
"node": "^18.19.0"
"node": ">=18.19.0"
},
"version": "0.0.0"
}
17 changes: 5 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4056,13 +4056,6 @@
dependencies:
"@types/node" "*"

"@types/adm-zip@^0.5.0":
version "0.5.5"
resolved "https://registry.npmjs.org/@types/adm-zip/-/adm-zip-0.5.5.tgz#4588042726aa5f351d7ea88232e4a952f60e7c1a"
integrity sha512-YCGstVMjc4LTY5uK9/obvxBya93axZOVOyf2GSUulADzmLhYE45u2nAssCs/fWBs1Ifq5Vat75JTPwd5XZoPJw==
dependencies:
"@types/node" "*"

"@types/babel__core@^7.0.0", "@types/babel__core@^7.1.14":
version "7.20.5"
resolved "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz#3df15f27ba85319caa07ba08d0721889bb39c017"
Expand Down Expand Up @@ -5704,6 +5697,11 @@
resolved "https://registry.npmjs.org/@yr/monotone-cubic-spline/-/monotone-cubic-spline-1.0.3.tgz#7272d89f8e4f6fb7a1600c28c378cc18d3b577b9"
integrity sha512-FQXkOta0XBSUPHndIKON2Y9JeQz5ZeMqLYZVVK93FliNBFm7LNMIZmY6FrMEB9XPcDbE2bekMbZD6kzDkxwYjA==

"@zip.js/zip.js@^2.7.47":
version "2.7.47"
resolved "https://registry.yarnpkg.com/@zip.js/zip.js/-/zip.js-2.7.47.tgz#bc3ec3d3b191f2331450242edfa06dfac08082cc"
integrity sha512-jmtJMA3/Jl4rMzo/DZ79s6g0CJ1AZcNAO6emTy/vHfIKAB/iiFY7PLs6KmbRTJ+F8GnK2eCLnjQfCCneRxXgzg==

"@zkochan/[email protected]":
version "0.0.6"
resolved "https://registry.npmjs.org/@zkochan/js-yaml/-/js-yaml-0.0.6.tgz#975f0b306e705e28b8068a07737fa46d3fc04826"
Expand Down Expand Up @@ -5802,11 +5800,6 @@ address@^1.1.2:
resolved "https://registry.npmjs.org/address/-/address-1.2.2.tgz#2b5248dac5485a6390532c6a517fda2e3faac89e"
integrity sha512-4B/qKCfeE/ODUaAUpSwfzazo5x29WD4r3vXiWsB7I2mSDAihwEqKO+g8GELZUQSSAo5e1XTYh3ZVfLyxBc12nA==

adm-zip@^0.5.10:
version "0.5.12"
resolved "https://registry.yarnpkg.com/adm-zip/-/adm-zip-0.5.12.tgz#87786328e91d54b37358d8a50f954c4cd73ba60b"
integrity sha512-6TVU49mK6KZb4qG6xWaaM4C7sA/sgUMLy/JYMOzkcp3BvVLpW0fXDFQiIzAuxFCt/2+xD7fNIiPFAoLZPhVNLQ==

agent-base@6:
version "6.0.2"
resolved "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77"
Expand Down
Loading