Edits history of script submission #17110 for ' Rebuild a config (linode)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Linode = {
      token: string;
    };
    /**
     * Rebuild a config
     * Rebuilds a NodeBalancer Config and its Nodes that you have permission to modify.
     */
    export async function main(
      auth: Linode,
      apiVersion: "v4" | "v4beta",
      nodeBalancerId: string,
      configId: string,
      body:
        | ({
            algorithm?: "roundrobin" | "leastconn" | "source";
            check?: "none" | "connection" | "http" | "http_body";
            check_attempts?: number;
            check_body?: string;
            check_interval?: number;
            check_passive?: false | true;
            check_path?: string;
            check_timeout?: number;
            cipher_suite?: string;
            id?: number;
            nodebalancer_id?: number;
            nodes: {
              address?: string;
              config_id?: number;
              id?: number;
              label?: string;
              mode?: "accept" | "reject" | "drain" | "backup";
              nodebalancer_id?: number;
              status?: "unknown" | "UP" | "DOWN";
              weight?: number;
            }[];
            nodes_status?: { down?: number; up?: number };
            port?: number;
            protocol?: "tcp";
            proxy_protocol?: "none" | "v1" | "v2";
            ssl_cert?: string;
            ssl_commonname?: string;
            ssl_fingerprint?: string;
            ssl_key?: string;
            stickiness?: "none" | "table";
          } & {
            nodes: {
              address?: string;
              id?: number;
              label?: string;
              mode?: "accept" | "reject" | "drain" | "backup";
              weight?: number;
            }[];
          })
        | ({
            algorithm?: "roundrobin" | "leastconn" | "source";
            check?: "none" | "connection" | "http" | "http_body";
            check_attempts?: number;
            check_body?: string;
            check_interval?: number;
            check_passive?: false | true;
            check_path?: string;
            check_timeout?: number;
            cipher_suite?: string;
            id?: number;
            nodebalancer_id?: number;
            nodes: {
              address?: string;
              config_id?: number;
              id?: number;
              label?: string;
              mode?: "accept" | "reject" | "drain" | "backup";
              nodebalancer_id?: number;
              status?: "unknown" | "UP" | "DOWN";
              weight?: number;
            }[];
            nodes_status?: { down?: number; up?: number };
            port?: number;
            protocol?: "http";
            proxy_protocol?: string;
            ssl_cert?: string;
            ssl_commonname?: string;
            ssl_fingerprint?: string;
            ssl_key?: string;
            stickiness?: "none" | "table" | "http_cookie";
          } & {
            nodes: {
              address?: string;
              id?: number;
              label?: string;
              mode?: "accept" | "reject" | "drain" | "backup";
              weight?: number;
            }[];
          })
        | ({
            algorithm?: "roundrobin" | "leastconn" | "source";
            check?: "none" | "connection" | "http" | "http_body";
            check_attempts?: number;
            check_body?: string;
            check_interval?: number;
            check_passive?: false | true;
            check_path?: string;
            check_timeout?: number;
            cipher_suite?: "recommended" | "legacy";
            id?: number;
            nodebalancer_id?: number;
            nodes: {
              address?: string;
              config_id?: number;
              id?: number;
              label?: string;
              mode?: "accept" | "reject" | "drain" | "backup";
              nodebalancer_id?: number;
              status?: "unknown" | "UP" | "DOWN";
              weight?: number;
            }[];
            nodes_status?: { down?: number; up?: number };
            port?: number;
            protocol?: "https";
            proxy_protocol?: string;
            ssl_cert?: string;
            ssl_commonname?: string;
            ssl_fingerprint?: string;
            ssl_key?: string;
            stickiness?: "none" | "table" | "http_cookie";
          } & {
            nodes: {
              address?: string;
              id?: number;
              label?: string;
              mode?: "accept" | "reject" | "drain" | "backup";
              weight?: number;
            }[];
          }),
    ) {
      const url = new URL(
        `https://api.linode.com/${apiVersion}/nodebalancers/${nodeBalancerId}/configs/${configId}/rebuild`,
      );
    
      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