lugger
Version:
Lugger is an automation framework running on customizable Typescript DSL
84 lines • 3.93 kB
JavaScript
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UnixSocketPost = exports.UnixSocketGet = void 0;
const ts_basis_1 = require("ts-basis");
const http_1 = __importDefault(require("http"));
function UnixSocketGet(socketPath, path, headers = {}, encoding = 'utf8') {
return (0, ts_basis_1.promise)(async (resolve, reject) => {
const headersTotal = {};
Object.assign(headersTotal, headers);
const req = http_1.default.get({ path, socketPath, headers: headersTotal });
req.once('error', reject);
req.once('response', async (res) => {
var _a, e_1, _b, _c;
const buffers = [];
try {
for (var _d = true, res_1 = __asyncValues(res), res_1_1; res_1_1 = await res_1.next(), _a = res_1_1.done, !_a; _d = true) {
_c = res_1_1.value;
_d = false;
const buf = _c;
buffers.push(buf);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_d && !_a && (_b = res_1.return)) await _b.call(res_1);
}
finally { if (e_1) throw e_1.error; }
}
resolve(Buffer.concat(buffers).toString(encoding));
});
});
}
exports.UnixSocketGet = UnixSocketGet;
function UnixSocketPost(socketPath, path, postData, headers = {}, encoding = 'utf8') {
return (0, ts_basis_1.promise)(async (resolve, reject) => {
const xStreamMatch = headers['X-Stream-Match'];
const headersTotal = Object.assign({}, headers);
if (headersTotal['X-Stream-Match']) {
delete headersTotal['X-Stream-Match'];
}
const req = http_1.default.request({ method: 'POST', path, socketPath, headers: headersTotal }, res => {
const buffers = [];
if (xStreamMatch) {
let matched = null;
const matchPatterns = xStreamMatch.split(' || ')
.map(a => ({ pattern: a.split(' :: ')[0], value: a.split(' :: ')[1] }));
res.on('data', chunk => {
if (matched) {
return;
}
for (const matcher of matchPatterns) {
if (chunk.toString('utf8').indexOf(matcher.pattern) >= 0) {
matched = matcher.value;
break;
}
}
});
res.on('end', () => { resolve(matched); });
}
else {
res.on('data', chunk => {
buffers.push(chunk);
});
res.on('end', () => { resolve(Buffer.concat(buffers).toString(encoding)); });
}
});
req.once('error', reject);
req.write(Buffer.from(postData, encoding));
req.end();
});
}
exports.UnixSocketPost = UnixSocketPost;
//# sourceMappingURL=docker.model.js.map
;