Skip to content

Commit

Permalink
feat(mast): CORE-5318 - Extend downloadPcap to support networkMonitor
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac Bowhay committed Oct 30, 2023
1 parent fa0f8e6 commit 94dfb19
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 94dfb19

Please sign in to comment.