type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Delete a tunnel route (CIDR Endpoint)
* Deletes a private network route from an account. The CIDR in `ip_network_encoded` must be written in URL-encoded format. If no virtual_network_id is provided it will delete the route from the default vnet. If no tun_type is provided it will fetch the type from the tunnel_id or if that is missing it will assume Cloudflare Tunnel as default. If tunnel_id is provided it will delete the route from that tunnel, otherwise it will delete the route based on the vnet and tun_type.
*/
export async function main(
auth: Cloudflare,
ip_network_encoded: string,
account_identifier: string,
virtual_network_id: string | undefined,
tun_type:
| "cfd_tunnel"
| "warp_connector"
| "ip_sec"
| "gre"
| "cni"
| undefined,
tunnel_id: string | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/accounts/${account_identifier}/teamnet/routes/network/${ip_network_encoded}`
);
for (const [k, v] of [
["virtual_network_id", virtual_network_id],
["tun_type", tun_type],
["tunnel_id", tunnel_id],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "DELETE",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
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;
};
/**
* Delete a tunnel route (CIDR Endpoint)
* Deletes a private network route from an account. The CIDR in `ip_network_encoded` must be written in URL-encoded format. If no virtual_network_id is provided it will delete the route from the default vnet. If no tun_type is provided it will fetch the type from the tunnel_id or if that is missing it will assume Cloudflare Tunnel as default. If tunnel_id is provided it will delete the route from that tunnel, otherwise it will delete the route based on the vnet and tun_type.
*/
export async function main(
auth: Cloudflare,
ip_network_encoded: string,
account_identifier: string,
virtual_network_id: string | undefined,
tun_type:
| "cfd_tunnel"
| "warp_connector"
| "ip_sec"
| "gre"
| "cni"
| undefined,
tunnel_id: string | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/accounts/${account_identifier}/teamnet/routes/network/${ip_network_encoded}`
);
for (const [k, v] of [
["virtual_network_id", virtual_network_id],
["tun_type", tun_type],
["tunnel_id", tunnel_id],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "DELETE",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 920 days ago