Clean unused variables

This commit is contained in:
Douglas Barone 2020-12-10 19:56:05 -04:00
parent a7322693d3
commit b77716ebc6

View File

@ -1,3 +1,5 @@
// Ref.: https://docs.paloaltonetworks.com/pan-os/9-1/pan-os-panorama-api/pan-os-xml-api-request-types/apply-user-id-mapping-and-populate-dynamic-address-groups-api.html
import axios from 'axios' import axios from 'axios'
import prisma from '../prisma' import prisma from '../prisma'
import https from 'https' import https from 'https'
@ -9,10 +11,10 @@ const httpsAgent = new https.Agent({
let working = false let working = false
const DEBOUNCE_TIME_MS = 10000 const DEBOUNCE_TIME_IN_MS = 5000
async function updateUserIdMappings() { async function updateUserIdMappings() {
if (working) return 0 if (working) return -1
working = true working = true
@ -29,43 +31,29 @@ async function updateUserIdMappings() {
}) })
const entries = wifiDevices.reduce( const entries = wifiDevices.reduce(
(entries, device, i) => (entries, device) =>
(entries += `<entry name="ifms\\${device.user.sAMAccountName}" ip="${device.ip}" timeout="5"/>`), (entries += `<entry name="ifms\\${device.user.sAMAccountName}" ip="${device.ip}" timeout="5"/>`),
'' ''
) )
const cmd = ` const cmd = `
<uid-message> <uid-message>
<version>1.0</version> <version>1.0</version>
<type>update</type> <type>update</type>
<payload> <payload>
<login> <login>
${entries} ${entries}
</login> </login>
</payload> </payload>
</uid-message> ` </uid-message>`
/* await axios({
https://docs.paloaltonetworks.com/pan-os/9-1/pan-os-panorama-api/pan-os-xml-api-request-types/apply-user-id-mapping-and-populate-dynamic-address-groups-api.html
Use a GET request if the URL query size is less than 2K and a POST request if the request size is between 2K to 5MB. Limit the query size to 5MB.
When multiple login or logout events are generated at the same time, make sure to follow these guidelines to ensure optimal firewall performance:
Design your application to queue events and perform batch API updates instead of sending single event or mapping updates.
Limit the number of concurrent API calls to five. This limit ensures that there is no performance impact to the firewall web interface as the management plane web server handles requests from both the API and the web interface.
*/
const result = await axios({
method: 'POST',
data: qs.stringify({
cmd
}),
url: `https://${process.env.PA_HOST}/api/`, url: `https://${process.env.PA_HOST}/api/`,
params: { method: 'POST',
type: 'user-id' params: { type: 'user-id' },
}, data: qs.stringify({ cmd }),
headers: { headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
'Content-Type': 'application/x-www-form-urlencoded'
},
auth: { auth: {
username: process.env.PA_USER, username: process.env.PA_USER,
password: process.env.PA_PASSWORD password: process.env.PA_PASSWORD
@ -75,12 +63,12 @@ async function updateUserIdMappings() {
return wifiDevices.length return wifiDevices.length
} catch (e) { } catch (e) {
console.log('Error updating user-id mappings:', e) console.log('Error updating user-id mappings:', e.message)
return 'Não foi possível atualizar. Veja o log do servidor' return 'Não foi possível atualizar. Veja o log do servidor'
} finally { } finally {
setTimeout(() => { setTimeout(() => {
working = false working = false
}, DEBOUNCE_TIME_MS) }, DEBOUNCE_TIME_IN_MS)
} }
} }