-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
62 lines (59 loc) · 1.99 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
import select from "@inquirer/select";
import chalk from "chalk";
import { program } from "commander";
import { retrieveSubscriptions } from "./az-commands/subscriptions.js";
import { retrieveStaticWebApps } from "./az-commands/swa.js";
import {
printConsoleReport,
writeCSVOutput,
writeJSONOutput,
} from "./print-utils.js";
import { scanSWAAndReport } from "./scanner/waf-scanner.js";
import type { SWA } from "./swa.types.js";
import { DefaultAzureCredential } from "@azure/identity";
program
.version("0.1.0")
.description(
"Welcome to Arcane Shield, a security tool to check the presence of a Web Application Firewall on static web site in your subscription.",
)
.option("-s, --subscription <id>", "ID of your Azure subscription")
.option("-o, --output <name>", "Output name", "scanReport.json")
.option(
"-f, --format <type>",
"Output format, accepted json, csv; default: json",
"json",
)
.action(async (options) => {
console.log(chalk.magentaBright.bold`Welcome to Arcane Shield`);
const creds = new DefaultAzureCredential();
const subscriptions = await retrieveSubscriptions(creds);
let selectedSubscription = options.subscription;
if (!selectedSubscription) {
selectedSubscription = await select({
message: "Select a subscription",
choices: subscriptions.map((subscription) => ({
name: subscription.name,
value: subscription.id,
description: `ID: ${subscription.id}`,
})),
});
}
const staticWebApps = await retrieveStaticWebApps(
creds,
selectedSubscription,
);
const enhancedSWAs: SWA[] = [];
for (const staticWebApp of staticWebApps) {
enhancedSWAs.push(await scanSWAAndReport(staticWebApp));
}
for (const swa of enhancedSWAs) {
printConsoleReport(swa);
}
if (options.format === "json") {
writeJSONOutput(options.output, selectedSubscription, enhancedSWAs);
} else if (options.format === "csv") {
writeCSVOutput(options.output, selectedSubscription, enhancedSWAs);
}
});
program.parse(process.argv);