1 | |
2 | type Cockroachdb = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List Users |
7 | * Can be used by the following roles assigned at the organization scope: |
8 | - ORG_ADMIN |
9 |
|
10 | */ |
11 | export async function main( |
12 | auth: Cockroachdb, |
13 | filter: string | undefined, |
14 | attributes: string | undefined, |
15 | excludedAttributes: string | undefined, |
16 | count: string | undefined, |
17 | startIndex: string | undefined, |
18 | ) { |
19 | const url = new URL(`https://cockroachlabs.cloud/api/scim/v2/Users`); |
20 | for (const [k, v] of [ |
21 | ["filter", filter], |
22 | ["attributes", attributes], |
23 | ["excludedAttributes", excludedAttributes], |
24 | ["count", count], |
25 | ["startIndex", startIndex], |
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 |
|