0
Add buckets for full packet captures
One script reply has been approved by the moderators Verified

Adds an AWS or GCP bucket to use with full packet captures.

Created by hugo697 151 days ago Viewed 3724 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 151 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Add buckets for full packet captures
8
 * Adds an AWS or GCP bucket to use with full packet captures.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  account_identifier: string,
13
  body: { destination_conf: string; [k: string]: unknown }
14
) {
15
  const url = new URL(
16
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/pcaps/ownership`
17
  );
18

19
  const response = await fetch(url, {
20
    method: "POST",
21
    headers: {
22
      "X-AUTH-EMAIL": auth.email,
23
      "X-AUTH-KEY": auth.key,
24
      "Content-Type": "application/json",
25
      Authorization: "Bearer " + auth.token,
26
    },
27
    body: JSON.stringify(body),
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35