Edits history of script submission #17182 for ' Update firewall rules (linode)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Linode = {
      token: string;
    };
    /**
     * Update firewall rules
     * Updates the inbound and outbound Rules for a Firewall.
     */
    export async function main(
      auth: Linode,
      apiVersion: "v4" | "v4beta",
      firewallId: string,
      body: {
        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;
      } & { inbound?: {}; outbound?: {} },
    ) {
      const url = new URL(
        `https://api.linode.com/${apiVersion}/networking/firewalls/${firewallId}/rules`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        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