0
Update ACL
One script reply has been approved by the moderators Verified

Modify ACL.

Created by hugo697 447 days ago Viewed 13319 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 447 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Update ACL
8
 * Modify ACL.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  identifier: string,
13
  account_identifier: string,
14
  body: {
15
    id: { [k: string]: unknown };
16
    ip_range: string;
17
    name: string;
18
    [k: string]: unknown;
19
  }
20
) {
21
  const url = new URL(
22
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/secondary_dns/acls/${identifier}`
23
  );
24

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