Edits history of script submission #10714 for ' Configure a Database Cluster's Maintenance Window (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Configure a Database Cluster's Maintenance Window
     * To configure the window when automatic maintenance should be performed for a database cluster, send a PUT request to `/v2/databases/$DATABASE_ID/maintenance`.
    A successful request will receive a 204 No Content status code with no body in response.
     */
    export async function main(
      auth: Digitalocean,
      database_cluster_uuid: string,
      body: {
        day: string;
        hour: string;
        pending?: false | true;
        description?: string[];
      },
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/maintenance`,
      );
    
      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