Edits history of script submission #16834 for ' Create a NodeBalancer (linode)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Linode = {
      token: string;
    };
    /**
     * Create a NodeBalancer
     * Creates a NodeBalancer in the requested Region.
     */
    export async function main(
      auth: Linode,
      apiVersion: "v4" | "v4beta",
      body: {
        client_conn_throttle?: number;
        configs?:
          | {
              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";
            }
          | {
              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";
            }
          | {
              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";
            }[];
        firewall_id?: number;
        label?: string;
        region: string;
        tags?: string[];
      },
    ) {
      const url = new URL(`https://api.linode.com/${apiVersion}/nodebalancers`);
    
      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