Edits history of script submission #11032 for ' Update a Database User (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Update a Database User
     * To update an existing database user, send a PUT request to `/v2/databases/$DATABASE_ID/users/$USERNAME`
    with the desired settings.
    
    **Note**: only `settings` can be updated via this type of request. If you wish to change the name of a user,
    you must recreate a new user.
    
    The response will be a JSON object with a key called `user`. The value of this will be an
    object that contains the name of the update database user, along with the `settings` object that
    has been updated.
    
     */
    export async function main(
      auth: Digitalocean,
      database_cluster_uuid: string,
      username: string,
      body: {
        settings?: {
          pg_allow_replication?: false | true;
          opensearch_acl?: {
            index?: string;
            permission?: "deny" | "admin" | "read" | "readwrite" | "write";
          }[];
          acl?: {
            id?: string;
            topic: string;
            permission: "admin" | "consume" | "produce" | "produceconsume";
          }[];
        };
      },
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/users/${username}`,
      );
    
      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