0

List all Database Users

by
Published Dec 20, 2024

To list all of the users for your database cluster, send a GET request to `/v2/databases/$DATABASE_ID/users`. Note: User management is not supported for Redis clusters. The result will be a JSON object with a `users` key. This will be set to an array of database user objects, each of which will contain the standard database user attributes. For MySQL clusters, additional options will be contained in the mysql_settings object.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * List all Database Users
7
 * To list all of the users for your database cluster, send a GET request to
8
`/v2/databases/$DATABASE_ID/users`.
9

10
Note: User management is not supported for Redis clusters.
11

12
The result will be a JSON object with a `users` key. This will be set to an array
13
of database user objects, each of which will contain the standard database user attributes.
14

15
For MySQL clusters, additional options will be contained in the mysql_settings object.
16

17
 */
18
export async function main(auth: Digitalocean, database_cluster_uuid: string) {
19
  const url = new URL(
20
    `https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/users`,
21
  );
22

23
  const response = await fetch(url, {
24
    method: "GET",
25
    headers: {
26
      Authorization: "Bearer " + auth.token,
27
    },
28
    body: undefined,
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36