Add per-device VPN and direct routing policies
This commit is contained in:
@@ -1,9 +1,18 @@
|
||||
import http from 'node:http';
|
||||
import { HarborError } from '../shared/errors.js';
|
||||
|
||||
function request(socketPath, pathname, method = 'GET') {
|
||||
function request(socketPath, pathname, method = 'GET', body = null) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = http.request({ socketPath, path: pathname, method }, (res) => {
|
||||
const encoded = body == null ? null : JSON.stringify(body);
|
||||
const req = http.request({
|
||||
socketPath,
|
||||
path: pathname,
|
||||
method,
|
||||
headers: encoded ? {
|
||||
'content-type': 'application/json',
|
||||
'content-length': Buffer.byteLength(encoded),
|
||||
} : {},
|
||||
}, (res) => {
|
||||
const chunks = [];
|
||||
res.on('data', (chunk) => chunks.push(chunk));
|
||||
res.on('end', () => {
|
||||
@@ -21,7 +30,7 @@ function request(socketPath, pathname, method = 'GET') {
|
||||
});
|
||||
req.on('error', reject);
|
||||
req.setTimeout(6000, () => req.destroy(new Error('Dataplane не ответил за 6 секунд')));
|
||||
req.end();
|
||||
req.end(encoded);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -45,6 +54,8 @@ export function createDataplaneClient(socketPath, send = request) {
|
||||
refresh: () => update('/status', 'GET'),
|
||||
observeDevices: () => send(socketPath, '/devices', 'GET'),
|
||||
observeTraffic: () => send(socketPath, '/device-traffic', 'GET'),
|
||||
observeDevicePolicy: () => send(socketPath, '/device-policy', 'GET'),
|
||||
applyDevicePolicies: (devices) => send(socketPath, '/device-policy', 'PUT', { devices }),
|
||||
apply: () => update('/apply', 'POST'),
|
||||
restart: () => update('/restart', 'POST'),
|
||||
stop: () => update('/stop', 'POST'),
|
||||
|
||||
Reference in New Issue
Block a user