0

List all RoleGrants

by
Published Oct 17, 2025

Can be used by the following roles assigned at the organization scope: - ORG_ADMIN - CLUSTER_ADMIN - FOLDER_ADMIN

Script cockroachdb Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Cockroachdb = {
3
  token: string;
4
};
5
/**
6
 * List all RoleGrants
7
 * Can be used by the following roles assigned at the organization scope:
8
- ORG_ADMIN
9
- CLUSTER_ADMIN
10
- FOLDER_ADMIN
11

12
 */
13
export async function main(
14
  auth: Cockroachdb,
15
  pagination_page: string | undefined,
16
  pagination_limit: string | undefined,
17
  pagination_as_of_time: string | undefined,
18
  pagination_sort_order: "ASC" | "DESC" | undefined,
19
) {
20
  const url = new URL(`https://cockroachlabs.cloud/api/v1/roles`);
21
  for (const [k, v] of [
22
    ["pagination.page", pagination_page],
23
    ["pagination.limit", pagination_limit],
24
    ["pagination.as_of_time", pagination_as_of_time],
25
    ["pagination.sort_order", pagination_sort_order],
26
  ]) {
27
    if (v !== undefined && v !== "" && k !== undefined) {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44