type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Update an IP Access rule
* Updates an IP Access rule defined at the account level.
Note: This operation will affect all zones in the account.
*/
export async function main(
auth: Cloudflare,
identifier: string,
account_identifier: string,
body: {
allowed_modes: (
| "block"
| "challenge"
| "whitelist"
| "js_challenge"
| "managed_challenge"
)[];
configuration:
| { target?: "ip"; value?: string; [k: string]: unknown }
| { target?: "ip6"; value?: string; [k: string]: unknown }
| { target?: "ip_range"; value?: string; [k: string]: unknown }
| { target?: "asn"; value?: string; [k: string]: unknown }
| { target?: "country"; value?: string; [k: string]: unknown };
created_on?: string;
id: string;
mode:
| "block"
| "challenge"
| "whitelist"
| "js_challenge"
| "managed_challenge";
modified_on?: string;
notes?: string;
[k: string]: unknown;
} & {
scope?: {
email?: string;
id?: string;
type?: "user" | "organization";
[k: string]: unknown;
};
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/accounts/${account_identifier}/firewall/access_rules/rules/${identifier}`
);
const response = await fetch(url, {
method: "PATCH",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 383 days ago
type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Update an IP Access rule
* Updates an IP Access rule defined at the account level.
Note: This operation will affect all zones in the account.
*/
export async function main(
auth: Cloudflare,
identifier: string,
account_identifier: string,
body: {
allowed_modes: (
| "block"
| "challenge"
| "whitelist"
| "js_challenge"
| "managed_challenge"
)[];
configuration:
| { target?: "ip"; value?: string; [k: string]: unknown }
| { target?: "ip6"; value?: string; [k: string]: unknown }
| { target?: "ip_range"; value?: string; [k: string]: unknown }
| { target?: "asn"; value?: string; [k: string]: unknown }
| { target?: "country"; value?: string; [k: string]: unknown };
created_on?: string;
id: string;
mode:
| "block"
| "challenge"
| "whitelist"
| "js_challenge"
| "managed_challenge";
modified_on?: string;
notes?: string;
[k: string]: unknown;
} & {
scope?: {
email?: string;
id?: string;
type?: "user" | "organization";
[k: string]: unknown;
};
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/accounts/${account_identifier}/firewall/access_rules/rules/${identifier}`
);
const response = await fetch(url, {
method: "PATCH",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 920 days ago