Edits history of script submission #11035 for ' Update a Kubernetes Cluster (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Update a Kubernetes Cluster
     * To update a Kubernetes cluster, send a PUT request to
    `/v2/kubernetes/clusters/$K8S_CLUSTER_ID` and specify one or more of the
    attributes below.
    
     */
    export async function main(
      auth: Digitalocean,
      cluster_id: string,
      body: {
        name: string;
        tags?: string[];
        maintenance_policy?: {
          start_time?: string;
          duration?: string;
          day?:
            | "any"
            | "monday"
            | "tuesday"
            | "wednesday"
            | "thursday"
            | "friday"
            | "saturday"
            | "sunday";
        };
        auto_upgrade?: false | true;
        surge_upgrade?: false | true;
        ha?: false | true;
        control_plane_firewall?: {
          enable?: false | true;
          allowed_addresses?: string[];
        };
      },
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/kubernetes/clusters/${cluster_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 537 days ago