0

Retrieve an Existing Database User

by
Published Dec 20, 2024

To show information about an existing database user, send a GET request to `/v2/databases/$DATABASE_ID/users/$USERNAME`. Note: User management is not supported for Redis clusters. The response will be a JSON object with a `user` key. This will be set to an object containing the standard database user attributes. For MySQL clusters, additional options will be contained in the `mysql_settings` object. For Kafka clusters, additional options will be contained in the `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
 * Retrieve an Existing Database User
7
 * To show information about an existing database user, send a GET request to
8
`/v2/databases/$DATABASE_ID/users/$USERNAME`.
9

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

12
The response will be a JSON object with a `user` key. This will be set to an object
13
containing the standard database user attributes.
14

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

18
For Kafka clusters, additional options will be contained in the `settings` object.
19

20
 */
21
export async function main(
22
  auth: Digitalocean,
23
  database_cluster_uuid: string,
24
  username: string,
25
) {
26
  const url = new URL(
27
    `https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/users/${username}`,
28
  );
29

30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: undefined,
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43