0

List security policies

by
Published today

List Threat Defense security policies, one page at a time (offset/limit). Returns the page and next_offset (null on the last page).

Script infoblox_csp Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 6 hours ago
1
//native
2

3
/**
4
 * List security policies
5
 * List Threat Defense security policies, one page at a time. Filterable fields: id, name, description, is_default.
6
 */
7
export async function main(
8
  auth: RT.InfobloxCsp,
9
  filter: string | undefined,
10
  tag_filter: string | undefined,
11
  include_access_codes: boolean | undefined,
12
  offset: number | undefined,
13
  limit: number | undefined
14
) {
15
  const pageOffset = offset ?? 0
16
  const pageLimit = limit || 100
17
  const url = new URL(
18
    `${(auth.base_url || "https://csp.infoblox.com").replace(/\/+$/, "")}/api/atcfw/v1/security_policies`
19
  )
20
  if (filter != null && filter !== "") {
21
    url.searchParams.append("_filter", filter)
22
  }
23
  if (tag_filter != null && tag_filter !== "") {
24
    url.searchParams.append("_tfilter", tag_filter)
25
  }
26
  if (include_access_codes) {
27
    url.searchParams.append("include_access_codes", "true")
28
  }
29
  url.searchParams.append("_offset", String(pageOffset))
30
  url.searchParams.append("_limit", String(pageLimit))
31

32
  const response = await fetch(url, {
33
    method: "GET",
34
    headers: {
35
      Authorization: `Token ${auth.api_key}`,
36
      Accept: "application/json",
37
    },
38
  })
39

40
  if (!response.ok) {
41
    throw new Error(`${response.status} ${await response.text()}`)
42
  }
43

44
  const data = (await response.json()) as { results?: unknown[] }
45
  const results = data.results ?? []
46
  return {
47
    results,
48
    offset: pageOffset,
49
    limit: pageLimit,
50
    next_offset: results.length === pageLimit ? pageOffset + pageLimit : null,
51
  }
52
}
53