1 | type Cloudflare = { |
2 | token: string; |
3 | email: string; |
4 | key: string; |
5 | }; |
6 | |
7 | * Get layer 7 top target locations |
8 | * Get the top target locations of and by layer 7 attacks. Values are a percentage out of the total layer 7 attacks. The target location is determined by the attacked zone's billing country, when available. |
9 | */ |
10 | export async function main( |
11 | auth: Cloudflare, |
12 | limit: string | undefined, |
13 | name: string | undefined, |
14 | dateRange: string | undefined, |
15 | dateStart: string | undefined, |
16 | dateEnd: string | undefined, |
17 | format: "JSON" | "CSV" | undefined |
18 | ) { |
19 | const url = new URL( |
20 | `https://api.cloudflare.com/client/v4/radar/attacks/layer7/top/locations/target` |
21 | ); |
22 | for (const [k, v] of [ |
23 | ["limit", limit], |
24 | ["name", name], |
25 | ["dateRange", dateRange], |
26 | ["dateStart", dateStart], |
27 | ["dateEnd", dateEnd], |
28 | ["format", format], |
29 | ]) { |
30 | if (v !== undefined && v !== "") { |
31 | url.searchParams.append(k, v); |
32 | } |
33 | } |
34 | const response = await fetch(url, { |
35 | method: "GET", |
36 | headers: { |
37 | "X-AUTH-EMAIL": auth.email, |
38 | "X-AUTH-KEY": auth.key, |
39 | Authorization: "Bearer " + auth.token, |
40 | }, |
41 | body: undefined, |
42 | }); |
43 | if (!response.ok) { |
44 | const text = await response.text(); |
45 | throw new Error(`${response.status} ${text}`); |
46 | } |
47 | return await response.json(); |
48 | } |
49 |
|