0

List all egress rules associated with a cluster

by
Published Oct 17, 2025

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

Script cockroachdb Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Cockroachdb = {
3
  token: string;
4
};
5
/**
6
 * List all egress rules associated with a cluster
7
 * Sort order: Name
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

13
 */
14
export async function main(
15
  auth: Cockroachdb,
16
  cluster_id: string,
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(
23
    `https://cockroachlabs.cloud/api/v1/clusters/${cluster_id}/networking/egress-rules`,
24
  );
25
  for (const [k, v] of [
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