Edits history of script submission #24118 for ' Create named list (infoblox_csp)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create named list
     * 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.
     */
    export async function main(
      auth: RT.InfobloxCsp,
      name: string,
      items: string[] | undefined,
      items_described: { item: string; description?: string }[] | undefined,
      description: string | undefined,
      confidence_level: "LOW" | "MEDIUM" | "HIGH" | undefined,
      threat_level: "INFO" | "LOW" | "MEDIUM" | "HIGH" | undefined,
      tags: { [key: string]: any } | undefined
    ) {
      if (!items?.length && !items_described?.length) {
        throw new Error("Provide at least one entry in items or items_described")
      }
    
      const url = new URL(
        `${(auth.base_url || "https://csp.infoblox.com").replace(/\/+$/, "")}/api/atcfw/v1/named_lists`
      )
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: `Token ${auth.api_key}`,
          "Content-Type": "application/json",
          Accept: "application/json",
        },
        body: JSON.stringify({
          name,
          type: "custom_list",
          items: items?.length ? items : undefined,
          items_described: items_described?.length ? items_described : undefined,
          description: description || undefined,
          confidence_level: confidence_level || undefined,
          threat_level: threat_level || undefined,
          tags: tags && Object.keys(tags).length ? tags : undefined,
        }),
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 6 hours ago