0

Create named list

by
Published today

Create a Threat Defense custom list of FQDNs or IP addresses/CIDRs.

Script infoblox_csp Verified

The script

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

3
/**
4
 * Create named list
5
 * Create a Threat Defense custom list of FQDNs or IPv4/IPv6 addresses/CIDRs. Provide items, items_described (item + description), or both; at least one is required.
6
 */
7
export async function main(
8
  auth: RT.InfobloxCsp,
9
  name: string,
10
  items: string[] | undefined,
11
  items_described: { item: string; description?: string }[] | undefined,
12
  description: string | undefined,
13
  confidence_level: "LOW" | "MEDIUM" | "HIGH" | undefined,
14
  threat_level: "INFO" | "LOW" | "MEDIUM" | "HIGH" | undefined,
15
  tags: { [key: string]: any } | undefined
16
) {
17
  if (!items?.length && !items_described?.length) {
18
    throw new Error("Provide at least one entry in items or items_described")
19
  }
20

21
  const url = new URL(
22
    `${(auth.base_url || "https://csp.infoblox.com").replace(/\/+$/, "")}/api/atcfw/v1/named_lists`
23
  )
24

25
  const response = await fetch(url, {
26
    method: "POST",
27
    headers: {
28
      Authorization: `Token ${auth.api_key}`,
29
      "Content-Type": "application/json",
30
      Accept: "application/json",
31
    },
32
    body: JSON.stringify({
33
      name,
34
      type: "custom_list",
35
      items: items?.length ? items : undefined,
36
      items_described: items_described?.length ? items_described : undefined,
37
      description: description || undefined,
38
      confidence_level: confidence_level || undefined,
39
      threat_level: threat_level || undefined,
40
      tags: tags && Object.keys(tags).length ? tags : undefined,
41
    }),
42
  })
43

44
  if (!response.ok) {
45
    throw new Error(`${response.status} ${await response.text()}`)
46
  }
47

48
  return await response.json()
49
}
50