Edits history of script submission #10705 for ' Add a Database User (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Add a Database User
     * To add a new database user, send a POST request to `/v2/databases/$DATABASE_ID/users`
    with the desired username.
     */
    export async function main(
      auth: Digitalocean,
      database_cluster_uuid: string,
      body: {
        name: string;
        role?: "primary" | "normal";
        password?: string;
        access_cert?: string;
        access_key?: string;
        mysql_settings?: {
          auth_plugin: "mysql_native_password" | "caching_sha2_password";
        };
        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";
          }[];
        };
      } & { readonly?: false | true },
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/users`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        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