Edits history of script submission #11036 for ' Update a Load Balancer (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Update a Load Balancer
     * To update a load balancer's settings, send a PUT request to
    `/v2/load_balancers/$LOAD_BALANCER_ID`. The request should contain a full
    representation of the load balancer including existing attributes. It may
    contain _one of_ the `droplets_ids` or `tag` attributes as they are mutually
    exclusive. **Note that any attribute that is not provided will be reset to its
    default value.**
    
     */
    export async function main(
      auth: Digitalocean,
      lb_id: string,
      body:
        | ({ droplet_ids?: number[] } & {
            region?:
              | "ams1"
              | "ams2"
              | "ams3"
              | "blr1"
              | "fra1"
              | "lon1"
              | "nyc1"
              | "nyc2"
              | "nyc3"
              | "sfo1"
              | "sfo2"
              | "sfo3"
              | "sgp1"
              | "tor1"
              | "syd1";
          } & {
            id?: string;
            name?: string;
            project_id?: string;
            ip?: string;
            size_unit?: number;
            size?: "lb-small" | "lb-medium" | "lb-large";
            algorithm?: "round_robin" | "least_connections";
            status?: "new" | "active" | "errored";
            created_at?: string;
            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;
            }[];
            health_check?: {
              protocol?: "http" | "https" | "tcp";
              port?: number;
              path?: string;
              check_interval_seconds?: number;
              response_timeout_seconds?: number;
              unhealthy_threshold?: number;
              healthy_threshold?: number;
            };
            sticky_sessions?: {
              type?: "cookies" | "none";
              cookie_name?: string;
              cookie_ttl_seconds?: number;
            };
            redirect_http_to_https?: false | true;
            enable_proxy_protocol?: false | true;
            enable_backend_keepalive?: false | true;
            http_idle_timeout_seconds?: number;
            vpc_uuid?: string;
            disable_lets_encrypt_dns_records?: false | true;
            firewall?: { deny?: string[]; allow?: string[] };
            network?: "EXTERNAL" | "INTERNAL";
          })
        | ({ tag?: string } & {
            region?:
              | "ams1"
              | "ams2"
              | "ams3"
              | "blr1"
              | "fra1"
              | "lon1"
              | "nyc1"
              | "nyc2"
              | "nyc3"
              | "sfo1"
              | "sfo2"
              | "sfo3"
              | "sgp1"
              | "tor1"
              | "syd1";
          } & {
            id?: string;
            name?: string;
            project_id?: string;
            ip?: string;
            size_unit?: number;
            size?: "lb-small" | "lb-medium" | "lb-large";
            algorithm?: "round_robin" | "least_connections";
            status?: "new" | "active" | "errored";
            created_at?: string;
            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;
            }[];
            health_check?: {
              protocol?: "http" | "https" | "tcp";
              port?: number;
              path?: string;
              check_interval_seconds?: number;
              response_timeout_seconds?: number;
              unhealthy_threshold?: number;
              healthy_threshold?: number;
            };
            sticky_sessions?: {
              type?: "cookies" | "none";
              cookie_name?: string;
              cookie_ttl_seconds?: number;
            };
            redirect_http_to_https?: false | true;
            enable_proxy_protocol?: false | true;
            enable_backend_keepalive?: false | true;
            http_idle_timeout_seconds?: number;
            vpc_uuid?: string;
            disable_lets_encrypt_dns_records?: false | true;
            firewall?: { deny?: string[]; allow?: string[] };
            network?: "EXTERNAL" | "INTERNAL";
          }),
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/load_balancers/${lb_id}`,
      );
    
      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 536 days ago