0

Get the IP allowlist and propagation status for a cluster

by
Published Oct 17, 2025

Sort order: CIDR address Can be used by the following roles assigned at the organization, folder or cluster scope: - CLUSTER_ADMIN - CLUSTER_OPERATOR_WRITER - CLUSTER_DEVELOPER

Script cockroachdb Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Cockroachdb = {
3
  token: string;
4
};
5
/**
6
 * Get the IP allowlist and propagation status for a cluster
7
 * Sort order: CIDR address
8

9
Can be used by the following roles assigned at the organization, folder or cluster scope:
10
- CLUSTER_ADMIN
11
- CLUSTER_OPERATOR_WRITER
12
- CLUSTER_DEVELOPER
13

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