-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfortigateApiRequests.ts
34 lines (33 loc) · 1.05 KB
/
fortigateApiRequests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import axios from 'axios';
import https from 'https';
export class FortiGateAPIRequests {
private path: string;
private FORTIGATE_IP: string;
private API_KEY: string;
private rejectCerts: boolean;
constructor(path: string, FORTIGATE_IP: string, API_KEY: string, rejectCerts: boolean) {
this.path = path;
this.FORTIGATE_IP = FORTIGATE_IP;
this.API_KEY = API_KEY;
this.rejectCerts = rejectCerts;
}
public async httpsGetRequest() {
var url = 'https://' + this.FORTIGATE_IP + this.path;
const agent = new https.Agent({
rejectUnauthorized: this.rejectCerts
});
var options = {
httpsAgent: agent,
headers: {
Authorization: 'Bearer ' + this.API_KEY
}
};
try {
const response = await axios.get(url, options);
return response.data;
} catch (err) {
console.log(err);
}
throw console.error(`Error retrieving VIP data from Fortigate: ${url} `);
}
}