0

List named lists

by
Published today

List Threat Defense named lists, 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 named lists
5
 * List Threat Defense named lists (custom lists and Infoblox-managed feeds), one page at a time. Items are not included; use Get named list for them. The filter supports type (== / !=), items (~ / !~) and items_described (==), e.g. type=='custom_list'.
6
 */
7
export async function main(
8
  auth: RT.InfobloxCsp,
9
  filter: string | undefined,
10
  tag_filter: string | undefined,
11
  offset: number | undefined,
12
  limit: number | undefined
13
) {
14
  const pageOffset = offset ?? 0
15
  const pageLimit = limit || 100
16
  const url = new URL(
17
    `${(auth.base_url || "https://csp.infoblox.com").replace(/\/+$/, "")}/api/atcfw/v1/named_lists`
18
  )
19
  if (filter != null && filter !== "") {
20
    url.searchParams.append("_filter", filter)
21
  }
22
  if (tag_filter != null && tag_filter !== "") {
23
    url.searchParams.append("_tfilter", tag_filter)
24
  }
25
  url.searchParams.append("_offset", String(pageOffset))
26
  url.searchParams.append("_limit", String(pageLimit))
27

28
  const response = await fetch(url, {
29
    method: "GET",
30
    headers: {
31
      Authorization: `Token ${auth.api_key}`,
32
      Accept: "application/json",
33
    },
34
  })
35

36
  if (!response.ok) {
37
    throw new Error(`${response.status} ${await response.text()}`)
38
  }
39

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