//native
type Linode = {
token: string;
};
/**
* Create a firewall
* Creates a Firewall to filter network traffic.
*/
export async function main(
auth: Linode,
apiVersion: "v4" | "v4beta",
body: {
created?: string;
id?: number;
label?: string;
rules?: {
fingerprint?: string;
inbound?: {
action?: "ACCEPT" | "DROP";
addresses?: { ipv4?: string[]; ipv6?: string[] };
description?: string;
label?: string;
ports?: string;
protocol?: "TCP" | "UDP" | "ICMP" | "IPENCAP";
}[];
inbound_policy?: "ACCEPT" | "DROP";
outbound?: {
action?: "ACCEPT" | "DROP";
addresses?: { ipv4?: string[]; ipv6?: string[] };
description?: string;
label?: string;
ports?: string;
protocol?: "TCP" | "UDP" | "ICMP" | "IPENCAP";
}[];
outbound_policy?: "ACCEPT" | "DROP";
version?: number;
};
status?: "enabled" | "disabled" | "deleted";
tags?: string[];
updated?: string;
} & {
devices?: { linodes?: number[]; nodebalancers?: number[] };
rules: { inbound?: {}; outbound?: {} };
},
) {
const url = new URL(
`https://api.linode.com/${apiVersion}/networking/firewalls`,
);
const response = await fetch(url, {
method: "POST",
headers: {
"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 235 days ago