Update DNS Firewall Cluster

Modify a DNS Firewall Cluster configuration.

Script cloudflare Verified

by hugo697 ยท 11/16/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Update DNS Firewall Cluster
8
 * Modify a DNS Firewall Cluster configuration.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  identifier: string,
13
  account_identifier: string,
14
  body: {
15
    attack_mitigation?: {
16
      enabled?: boolean;
17
      only_when_origin_unhealthy?: { [k: string]: unknown };
18
      only_when_upstream_unhealthy?: boolean;
19
      [k: string]: unknown;
20
    };
21
    deprecate_any_requests: boolean;
22
    dns_firewall_ips: (string | string)[];
23
    ecs_fallback: boolean;
24
    id: string;
25
    maximum_cache_ttl: number;
26
    minimum_cache_ttl: number;
27
    modified_on: string;
28
    name: string;
29
    negative_cache_ttl?: number;
30
    origin_ips?: { [k: string]: unknown };
31
    ratelimit?: number;
32
    retries?: number;
33
    upstream_ips: (string | string)[];
34
    [k: string]: unknown;
35
  }
36
) {
37
  const url = new URL(
38
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/dns_firewall/${identifier}`
39
  );
40

41
  const response = await fetch(url, {
42
    method: "PATCH",
43
    headers: {
44
      "X-AUTH-EMAIL": auth.email,
45
      "X-AUTH-KEY": auth.key,
46
      "Content-Type": "application/json",
47
      Authorization: "Bearer " + auth.token,
48
    },
49
    body: JSON.stringify(body),
50
  });
51
  if (!response.ok) {
52
    const text = await response.text();
53
    throw new Error(`${response.status} ${text}`);
54
  }
55
  return await response.json();
56
}
57