From 94dfb19757438c55915b2b806e7e533e84d73c7e Mon Sep 17 00:00:00 2001 From: Zac Bowhay Date: Mon, 30 Oct 2023 16:19:35 -0600 Subject: [PATCH] feat(mast): CORE-5318 - Extend downloadPcap to support networkMonitor --- src/instance.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/instance.js b/src/instance.js index f2eece1..67de082 100644 --- a/src/instance.js +++ b/src/instance.js @@ -455,16 +455,20 @@ class Instance extends EventEmitter { } /** - * Download netdump pcap file. + * Download specified pcap file. If pcapFile is not given or is invalid, default to netdump.pcap * @example - * let pcap = await instance.downloadPcap(); + * const pcap = await instance.downloadPcap(); * console.log(pcap.toString()); */ - async downloadPcap () { - const token = await this._fetch('/netdumpPcap-authorize', { method: 'POST' }) - const response = await fetchApi(this.project, '/preauthed/' + token.token + '/netdump.pcap', { - response: 'raw' - }) + async downloadPcap (pcapFile) { + const availablePcaps = { + networkMonitor: { preAuth: '/networkMonitorPcap-authorize', pcapFile: 'networkMonitor.pcap' }, + netdump: { preAuth: '/netdumpPcap-authorize', pcapFile: 'netdump.pcap' } + } + + const pcap = (typeof pcapFile === 'string' && availablePcaps[pcapFile]) || availablePcaps.netdump + const token = await this._fetch(pcap.preAuth, { method: 'POST' }) + const response = await fetchApi(this.project, `/preauthed/${token.token}/${pcap.pcapFile}`, { response: 'raw' }) return await response.buffer() }