Edits history of script submission #17153 for ' Update a config (linode)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Linode = {
      token: string;
    };
    /**
     * Update a config
     * Updates the configuration for a single port on a NodeBalancer.
     */
    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_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_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_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";
          },
    ) {
      const url = new URL(
        `https://api.linode.com/${apiVersion}/nodebalancers/${nodeBalancerId}/configs/${configId}`,
      );
    
      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