Skip to content

Commit fb31f53

Browse files
committed
WIP
1 parent 38dbcf9 commit fb31f53

1 file changed

Lines changed: 25 additions & 31 deletions

File tree

src/extension/index.ts

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,34 @@ export async function activate(context: ExtensionContext) {
5656

5757
// URI handler
5858
window.registerUriHandler({
59-
async handleUri(uri: Uri) {
60-
const params = new URLSearchParams(uri.query);
61-
const alertRequestUri = params.get('requestUri');
62-
63-
if (alertRequestUri) {
64-
const url = new URL(alertRequestUri);
65-
if (url) {
66-
await loadAlertSarif(url);
67-
}
68-
}
59+
async handleUri() {
60+
startWebServer();
6961
}
7062
});
7163

64+
async function startWebServer() {
65+
const port = 4169;
66+
createServer((request, response) => {
67+
outputChannel.appendLine(`${request.method} request received for ${request.url}}`);
68+
if (request.method === 'POST') {
69+
const filePath = `${os.tmpdir}\\${(new Date()).getTime()}.sarif`;
70+
const stream = request
71+
//.pipe(meter(1024 * 1024)) // Cap at 1 MB
72+
.pipe(fs.createWriteStream(filePath));
73+
stream.on('finish', async () => {
74+
store.logs.push(...await loadLogs([Uri.file(filePath)]));
75+
if (store.results.length) panel.show();
76+
});
77+
78+
response.statusCode = 200;
79+
response.end();
80+
81+
}
82+
}).listen(port, () => {
83+
outputChannel.appendLine(`Server running at http://localhost:${port}`);
84+
});
85+
}
86+
7287
async function loadAlertSarif(url: URL) {
7388
try {
7489
//const azureAccount: AzureAccountExtensionApi = (<AzureAccountExtensionApi>extensions.getExtension('ms-vscode.azure-account')?.exports); //.getApi('1.0.0'); // = (<AzureExtensionApiProvider>extensions.getExtension('ms-vscode.azure-account')!.exports).getApi('1.0.0');
@@ -127,27 +142,6 @@ export async function activate(context: ExtensionContext) {
127142

128143
//await loadAlertSarif(new URL('https://advsec.codedev.ms/cmeyer/_apis/advancedsecurity/alerts/18/?project=ProjektEins&repository=1213f32a-071a-4282-b9a2-2f6141590138'));
129144

130-
const port = 4169;
131-
createServer((request, response) => {
132-
outputChannel.appendLine(`${request.method} request received for ${request.url}}`);
133-
if (request.method === 'POST') {
134-
const filePath = `${os.tmpdir}\\${(new Date()).getTime()}.sarif`;
135-
const stream = request
136-
//.pipe(meter(1024 * 1024)) // Cap at 1 MB
137-
.pipe(fs.createWriteStream(filePath));
138-
stream.on('finish', async () => {
139-
store.logs.push(...await loadLogs([Uri.file(filePath)]));
140-
if (store.results.length) panel.show();
141-
});
142-
143-
response.statusCode = 200;
144-
response.end();
145-
146-
}
147-
}).listen(port, () => {
148-
outputChannel.appendLine(`Server running at http://localhost:${port}`);
149-
});
150-
151145
// General Activation
152146
activateSarifStatusBarItem(disposables);
153147
activateDiagnostics(disposables, store, baser, outputChannel);

0 commit comments

Comments
 (0)