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