1 | |
2 | type Cockroachdb = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List SQL users for a cluster |
7 | * Sort order: Username |
8 |
|
9 | Can be used by the following roles assigned at the organization, folder or cluster scope: |
10 | - CLUSTER_ADMIN |
11 | - CLUSTER_OPERATOR_WRITER |
12 | - CLUSTER_DEVELOPER |
13 |
|
14 | */ |
15 | export async function main( |
16 | auth: Cockroachdb, |
17 | cluster_id: string, |
18 | pagination_page: string | undefined, |
19 | pagination_limit: string | undefined, |
20 | pagination_as_of_time: string | undefined, |
21 | pagination_sort_order: "ASC" | "DESC" | undefined, |
22 | ) { |
23 | const url = new URL( |
24 | `https://cockroachlabs.cloud/api/v1/clusters/${cluster_id}/sql-users`, |
25 | ); |
26 | for (const [k, v] of [ |
27 | ["pagination.page", pagination_page], |
28 | ["pagination.limit", pagination_limit], |
29 | ["pagination.as_of_time", pagination_as_of_time], |
30 | ["pagination.sort_order", pagination_sort_order], |
31 | ]) { |
32 | if (v !== undefined && v !== "" && k !== undefined) { |
33 | url.searchParams.append(k, v); |
34 | } |
35 | } |
36 | const response = await fetch(url, { |
37 | method: "GET", |
38 | headers: { |
39 | Authorization: "Bearer " + auth.token, |
40 | }, |
41 | body: undefined, |
42 | }); |
43 | if (!response.ok) { |
44 | const text = await response.text(); |
45 | throw new Error(`${response.status} ${text}`); |
46 | } |
47 | return await response.json(); |
48 | } |
49 |
|