1 | |
2 | type Cockroachdb = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List the regions available for new clusters and nodes |
7 | * Sort order: Distance (based on client IP address) |
8 |
|
9 | This endpoint may be used by any member of the organization. |
10 | */ |
11 | export async function main( |
12 | auth: Cockroachdb, |
13 | provider: "GCP" | "AWS" | "AZURE" | undefined, |
14 | serverless: string | undefined, |
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( |
21 | `https://cockroachlabs.cloud/api/v1/clusters/available-regions`, |
22 | ); |
23 | for (const [k, v] of [ |
24 | ["provider", provider], |
25 | ["serverless", serverless], |
26 | ["pagination.page", pagination_page], |
27 | ["pagination.limit", pagination_limit], |
28 | ["pagination.as_of_time", pagination_as_of_time], |
29 | ["pagination.sort_order", pagination_sort_order], |
30 | ]) { |
31 | if (v !== undefined && v !== "" && k !== undefined) { |
32 | url.searchParams.append(k, v); |
33 | } |
34 | } |
35 | const response = await fetch(url, { |
36 | method: "GET", |
37 | headers: { |
38 | Authorization: "Bearer " + auth.token, |
39 | }, |
40 | body: undefined, |
41 | }); |
42 | if (!response.ok) { |
43 | const text = await response.text(); |
44 | throw new Error(`${response.status} ${text}`); |
45 | } |
46 | return await response.json(); |
47 | } |
48 |
|