Edits history of script submission #10940 for ' Remove Forwarding Rules from a Load Balancer (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Remove Forwarding Rules from a Load Balancer
     * To remove forwarding rules from a load balancer instance, send a DELETE
    request to `/v2/load_balancers/$LOAD_BALANCER_ID/forwarding_rules`. In the
    body of the request, there should be a `forwarding_rules` attribute containing
    an array of rules to be removed.
    
    No response body will be sent back, but the response code will indicate
    success. Specifically, the response code will be a 204, which means that the
    action was successful with no returned body data.
    
     */
    export async function main(
      auth: Digitalocean,
      lb_id: string,
      body: {
        forwarding_rules: {
          entry_protocol: "http" | "https" | "http2" | "http3" | "tcp" | "udp";
          entry_port: number;
          target_protocol: "http" | "https" | "http2" | "tcp" | "udp";
          target_port: number;
          certificate_id?: string;
          tls_passthrough?: false | true;
        }[];
      },
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/load_balancers/${lb_id}/forwarding_rules`,
      );
    
      const response = await fetch(url, {
        method: "DELETE",
        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 537 days ago