Edits history of script submission #24120 for ' List named lists (infoblox_csp)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * List named lists
     * 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'.
     */
    export async function main(
      auth: RT.InfobloxCsp,
      filter: string | undefined,
      tag_filter: string | undefined,
      offset: number | undefined,
      limit: number | undefined
    ) {
      const pageOffset = offset ?? 0
      const pageLimit = limit || 100
      const url = new URL(
        `${(auth.base_url || "https://csp.infoblox.com").replace(/\/+$/, "")}/api/atcfw/v1/named_lists`
      )
      if (filter != null && filter !== "") {
        url.searchParams.append("_filter", filter)
      }
      if (tag_filter != null && tag_filter !== "") {
        url.searchParams.append("_tfilter", tag_filter)
      }
      url.searchParams.append("_offset", String(pageOffset))
      url.searchParams.append("_limit", String(pageLimit))
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: `Token ${auth.api_key}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      const data = (await response.json()) as { results?: unknown[] }
      const results = data.results ?? []
      return {
        results,
        offset: pageOffset,
        limit: pageLimit,
        next_offset: results.length === pageLimit ? pageOffset + pageLimit : null,
      }
    }
    

    Submitted by hugo989 6 hours ago