-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwingateUtilManager.mjs
36 lines (25 loc) · 1.15 KB
/
TwingateUtilManager.mjs
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
35
36
import {TwingateApiClient} from './TwingateApiClient.mjs';
import dotenvPkg from 'dotenv';
dotenvPkg.config();
let [tgAccount, tgApiKey] = [process.env.TG_ACCOUNT, process.env.TG_API_KEY]
const applicationName = "Twingate-tg-watch-api/0.0.1"
export class TwingateUtilManager {
constructor() {
this.apiClient = new TwingateApiClient(tgAccount, tgApiKey, {
applicationName
});
}
async lookupRemoteNetworkByName(remoteNetwork) {
return await this.apiClient.lookupRemoteNetworkByName(remoteNetwork)
}
async lookupGroupByName(group) {
return await this.apiClient.lookupGroupByName(group)
}
async fetchAllResourcesInRemoteNetwork(remoteNetwork, opts) {
let query = this.apiClient.getRootNodePagedQuery("RemoteNetworkResource", "remoteNetwork", "resources", ["id", "name", "address{value}"])
return await this.apiClient.fetchAllRootNodePages(query, {id: remoteNetwork});
}
async createResource(name, address, remoteNetworkId, protocols = null, groupIds = []) {
return await this.apiClient.createResource(name, address, remoteNetworkId, protocols, groupIds)
}
}