Edits history of script submission #24142 for ' Get network device (cisco_ise)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get network device
     * Get the full configuration of one network access device, by ID or by name. Set exactly one of device_id and name.
     */
    export async function main(
      auth: RT.CiscoIse,
      device_id: string | undefined,
      name: string | undefined
    ) {
      if (!device_id === !name) {
        throw new Error("Set exactly one of device_id and name")
      }
      const base = new URL(auth.base_url)
      if (auth.ers_port) base.port = String(auth.ers_port)
      const path = device_id
        ? `/ers/config/networkdevice/${encodeURIComponent(device_id)}`
        : `/ers/config/networkdevice/name/${encodeURIComponent(name!)}`
      const url = new URL(path, base)
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 6 hours ago