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