UNPKG

limacharlie

Version:

An API for limacharlie.io, a cloud hosted endpoint detection and response platform.

1,594 lines (1,362 loc) 48.9 kB
"use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var request = require("request-promise"); var zlib = require('zlib'); var Sensor = require("./Sensor"); var Spout = require("./Spout"); var Job = require("./Job"); var Payloads = require("./Payload"); var ROOT_URL = "https://api.limacharlie.io"; var API_VERSION = "v1"; var HTTP_UNAUTHORIZED = 401; var HTTP_BAD_REQUEST = 400; var HTTP_TOO_MANY_REQUESTS = 429; var Manager = function () { function Manager(oid, secretApiKey, invId, isInteractive, jwt, onAuthFailure, onError) { _classCallCheck(this, Manager); this._oid = oid; this._secretApiKey = secretApiKey; this._jwt = jwt; this._invId = invId; this._isInteractive = isInteractive; if (this._isInteractive && !this._invId) { throw new Error("Investigation ID must be set for interactive mode to be eneabled."); } this._spout = null; this._lastContinuationToken = null; // If the onAuthFailure callback is set, the internal renewal of // the JWT using the API key is disable. We assume the callback is // responsible for updating the JWT and setting it in manager._jwt. // The async callback receives no parameters, a reference to // this Manager. After callback, the API call will automatically // be retried like the normal API Key based behavior. this.onAuthFailure = onAuthFailure; this.onError = onError; if (this._isInteractive) { this._spout = new Spout(this, "event", null, null, this._invId, null, null, null, true); } this.payloads = new Payloads(this); } _createClass(Manager, [{ key: "_refreshJWT", value: function () { var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { var req, data; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.prev = 0; if (this._secretApiKey) { _context.next = 3; break; } throw new Error("API key not set."); case 3: req = { method: "POST", json: true, timeout: 5 * 1000, form: { oid: this._oid, secret: this._secretApiKey } }; _context.next = 6; return request("https://app.limacharlie.io/jwt", req); case 6: data = _context.sent; this._jwt = data.jwt; return _context.abrupt("return", true); case 11: _context.prev = 11; _context.t0 = _context["catch"](0); // eslint-disable-next-line no-console console.error("Failed to refresh the JWT: " + _context.t0); return _context.abrupt("return", false); case 15: case "end": return _context.stop(); } } }, _callee, this, [[0, 11]]); })); function _refreshJWT() { return _ref.apply(this, arguments); } return _refreshJWT; }() }, { key: "sleep", value: function sleep(ms) { return new Promise(function (resolve) { return setTimeout(resolve, ms); }); } }, { key: "_restCall", value: function _restCall(url, verb, params, timeout, altRoot) { if (!this._oid) { return; } if (!timeout) { timeout = 10 * 1000; } if (!params) { params = {}; } var req = { headers: { Authorization: "bearer " + this._jwt }, method: verb, qsStringifyOptions: { arrayFormat: "repeat" }, json: true, timeout: timeout }; if (verb === "GET") { req["qs"] = params; } else { req["form"] = params; } if (altRoot) { return request(altRoot + "/" + url, req); } return request(ROOT_URL + "/" + API_VERSION + "/" + url, req); } }, { key: "_apiCall", value: function () { var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(url, verb, params, isNoRetry, isThrowError, timeout, altRoot) { var errMessage; return regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: if (this._jwt) { _context2.next = 3; break; } _context2.next = 3; return this._refreshJWT(); case 3: _context2.prev = 3; _context2.next = 6; return this._restCall(url, verb, params, timeout, altRoot); case 6: return _context2.abrupt("return", _context2.sent); case 9: _context2.prev = 9; _context2.t0 = _context2["catch"](3); console.error(_context2.t0); errMessage = null; if (_context2.t0.error && _context2.t0.error.error) { errMessage = _context2.t0.error.error; } else { errMessage = _context2.t0.toString(); } if (typeof errMessage != "string" && "error" in errMessage) { errMessage = errMessage["error"]; } if (!(_context2.t0.statusCode === HTTP_UNAUTHORIZED && !isNoRetry)) { _context2.next = 26; break; } if (!this.onAuthFailure) { _context2.next = 21; break; } _context2.next = 19; return this.onAuthFailure(); case 19: _context2.next = 23; break; case 21: _context2.next = 23; return this._refreshJWT(); case 23: return _context2.abrupt("return", this._apiCall(url, verb, params, true)); case 26: if (!(_context2.t0.statusCode === HTTP_TOO_MANY_REQUESTS && !isNoRetry)) { _context2.next = 32; break; } _context2.next = 29; return this.sleep(10 * 1000); case 29: return _context2.abrupt("return", this._apiCall(url, verb, params, false)); case 32: if (!(errMessage.includes("RequestError") && !isNoRetry)) { _context2.next = 36; break; } _context2.next = 35; return this.sleep(1 * 1000); case 35: return _context2.abrupt("return", this._apiCall(url, verb, params, true)); case 36: if (this.onError) { this.onError(errMessage); } if (!isThrowError) { _context2.next = 39; break; } throw new Error(errMessage); case 39: case "end": return _context2.stop(); } } }, _callee2, this, [[3, 9]]); })); function _apiCall(_x, _x2, _x3, _x4, _x5, _x6, _x7) { return _ref2.apply(this, arguments); } return _apiCall; }() }, { key: "_unzip", value: function () { var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(data, isBinary) { return regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: return _context3.abrupt("return", new Promise(function (resolve, reject) { zlib.unzip(data, function (err, buffer) { if (err) { return reject(err); } resolve(buffer.toString(isBinary ? 'binary' : 'utf8')); }); })); case 1: case "end": return _context3.stop(); } } }, _callee3, this); })); function _unzip(_x8, _x9) { return _ref3.apply(this, arguments); } return _unzip; }() }, { key: "shutdown", value: function shutdown() { if (this._spout) { this._spout.shutdown(); } } }, { key: "testAuth", value: function testAuth() { return this._refreshJWT(); } }, { key: "sensor", value: function sensor(sid, invId) { var s = new Sensor(this, sid); if (invId) { s.setInvId(invId); } else if (this._invId) { s.setInvId(this._invId); } return s; } }, { key: "sensors", value: function () { var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(invId, isNext) { var _this = this; var params, data, thisInv; return regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: params = {}; if (!isNext) { _context4.next = 6; break; } if (this._lastContinuationToken) { _context4.next = 4; break; } return _context4.abrupt("return", []); case 4: params["continuation_token"] = this._lastContinuationToken; this._lastContinuationToken = null; case 6: _context4.next = 8; return this._apiCall("sensors/" + this._oid, "GET", params); case 8: data = _context4.sent; if (data.continuation_token) { this._lastContinuationToken = data.continuation_token; } thisInv = invId; if (!thisInv) { thisInv = this._invId; } return _context4.abrupt("return", data.sensors.map(function (s) { return _this.sensor(s.sid, thisInv); })); case 13: case "end": return _context4.stop(); } } }, _callee4, this); })); function sensors(_x10, _x11) { return _ref4.apply(this, arguments); } return sensors; }() }, { key: "getAvailableEvents", value: function () { var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() { return regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: _context5.next = 2; return this._apiCall("events", "GET"); case 2: return _context5.abrupt("return", _context5.sent.events); case 3: case "end": return _context5.stop(); } } }, _callee5, this); })); function getAvailableEvents() { return _ref5.apply(this, arguments); } return getAvailableEvents; }() }, { key: "getAutoComplete", value: function () { var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(aid) { var params; return regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: params = null; if (aid) { params = { aid: aid }; } _context6.next = 4; return this._apiCall("autocomplete/task", "GET", params); case 4: return _context6.abrupt("return", _context6.sent); case 5: case "end": return _context6.stop(); } } }, _callee6, this); })); function getAutoComplete(_x12) { return _ref6.apply(this, arguments); } return getAutoComplete; }() }, { key: "getSensorsWithHostname", value: function () { var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(hostnamePrefix) { var data; return regeneratorRuntime.wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: _context7.next = 2; return this._apiCall("hostnames/" + this._oid, "GET", { hostname: hostnamePrefix }); case 2: data = _context7.sent; return _context7.abrupt("return", data.sid); case 4: case "end": return _context7.stop(); } } }, _callee7, this); })); function getSensorsWithHostname(_x13) { return _ref7.apply(this, arguments); } return getSensorsWithHostname; }() }, { key: "isInsightEnabled", value: function () { var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() { var insightConfig; return regeneratorRuntime.wrap(function _callee8$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: _context8.next = 2; return this._apiCall("insight/" + this._oid, "GET"); case 2: insightConfig = _context8.sent; if (!(insightConfig && "insight_bucket" in insightConfig && insightConfig["insight_bucket"])) { _context8.next = 5; break; } return _context8.abrupt("return", true); case 5: return _context8.abrupt("return", false); case 6: case "end": return _context8.stop(); } } }, _callee8, this); })); function isInsightEnabled() { return _ref8.apply(this, arguments); } return isInsightEnabled; }() }, { key: "getHistoricDetections", value: function () { var _ref9 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9(params) { var data; return regeneratorRuntime.wrap(function _callee9$(_context9) { while (1) { switch (_context9.prev = _context9.next) { case 0: if (!params) { params = {}; } params["is_compressed"] = "true"; _context9.next = 4; return this._apiCall("insight/" + this._oid + "/detections", "GET", params, false, false, 30 * 1000); case 4: data = _context9.sent; _context9.next = 7; return this._unzip(Buffer.from(data.detects, "base64")); case 7: data.events = _context9.sent; data.events = JSON.parse(data.events); return _context9.abrupt("return", data); case 10: case "end": return _context9.stop(); } } }, _callee9, this); })); function getHistoricDetections(_x14) { return _ref9.apply(this, arguments); } return getHistoricDetections; }() }, { key: "deleteAllHistoricDetections", value: function () { var _ref10 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() { var data; return regeneratorRuntime.wrap(function _callee10$(_context10) { while (1) { switch (_context10.prev = _context10.next) { case 0: _context10.next = 2; return this._apiCall("insight/" + this._oid + "/detections", "DELETE", {}, false, false, 60 * 1000 * 10); case 2: data = _context10.sent; return _context10.abrupt("return", data); case 4: case "end": return _context10.stop(); } } }, _callee10, this); })); function deleteAllHistoricDetections() { return _ref10.apply(this, arguments); } return deleteAllHistoricDetections; }() }, { key: "getObjectInformation", value: function () { var _ref11 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11(objType, objName, params) { var data; return regeneratorRuntime.wrap(function _callee11$(_context11) { while (1) { switch (_context11.prev = _context11.next) { case 0: if (!params) { params = {}; } params["name"] = objName; _context11.next = 4; return this._apiCall("insight/" + this._oid + "/objects/" + objType, "GET", params); case 4: data = _context11.sent; return _context11.abrupt("return", data); case 6: case "end": return _context11.stop(); } } }, _callee11, this); })); function getObjectInformation(_x15, _x16, _x17) { return _ref11.apply(this, arguments); } return getObjectInformation; }() }, { key: "getObjectBatchInformation", value: function () { var _ref12 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12(objects, params) { var data; return regeneratorRuntime.wrap(function _callee12$(_context12) { while (1) { switch (_context12.prev = _context12.next) { case 0: if (!params) { params = {}; } params["objects"] = JSON.stringify(objects); _context12.next = 4; return this._apiCall("insight/" + this._oid + "/objects", "POST", params); case 4: data = _context12.sent; return _context12.abrupt("return", data); case 6: case "end": return _context12.stop(); } } }, _callee12, this); })); function getObjectBatchInformation(_x18, _x19) { return _ref12.apply(this, arguments); } return getObjectBatchInformation; }() }, { key: "getObjectBaseline", value: function () { var _ref13 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13() { var winBin, macBin, objects; return regeneratorRuntime.wrap(function _callee13$(_context13) { while (1) { switch (_context13.prev = _context13.next) { case 0: winBin = "ntdll.dll"; macBin = "launchd"; _context13.next = 4; return this.getObjectBatchInformation({ file_name: [winBin, macBin] }); case 4: objects = _context13.sent; return _context13.abrupt("return", { windows: { last_1_days: objects.last_1_days.file_name[winBin], last_7_days: objects.last_7_days.file_name[winBin], last_30_days: objects.last_30_days.file_name[winBin] }, mac: { last_1_days: objects.last_1_days.file_name[macBin], last_7_days: objects.last_7_days.file_name[macBin], last_30_days: objects.last_30_days.file_name[macBin] } }); case 6: case "end": return _context13.stop(); } } }, _callee13, this); })); function getObjectBaseline() { return _ref13.apply(this, arguments); } return getObjectBaseline; }() }, { key: "getTrafficBreakdown", value: function () { var _ref14 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14(start, end) { var data; return regeneratorRuntime.wrap(function _callee14$(_context14) { while (1) { switch (_context14.prev = _context14.next) { case 0: _context14.next = 2; return this._apiCall("insight/" + this._oid + "/traffic/breakdown", "GET", { start: start, end: end }); case 2: data = _context14.sent; return _context14.abrupt("return", data); case 4: case "end": return _context14.stop(); } } }, _callee14, this); })); function getTrafficBreakdown(_x20, _x21) { return _ref14.apply(this, arguments); } return getTrafficBreakdown; }() }, { key: "getOnlineStats", value: function () { var _ref15 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee15(start, end, sid) { var params, data; return regeneratorRuntime.wrap(function _callee15$(_context15) { while (1) { switch (_context15.prev = _context15.next) { case 0: params = { start: start, end: end }; if (sid) { params["sid"] = sid; } _context15.next = 4; return this._apiCall("insight/" + this._oid + "/online/stats", "GET", params); case 4: data = _context15.sent; return _context15.abrupt("return", data); case 6: case "end": return _context15.stop(); } } }, _callee15, this); })); function getOnlineStats(_x22, _x23, _x24) { return _ref15.apply(this, arguments); } return getOnlineStats; }() }, { key: "getTrafficStats", value: function () { var _ref16 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee16(start, end, sid) { var params, data; return regeneratorRuntime.wrap(function _callee16$(_context16) { while (1) { switch (_context16.prev = _context16.next) { case 0: params = { start: start, end: end }; if (sid) { params["sid"] = sid; } _context16.next = 4; return this._apiCall("insight/" + this._oid + "/traffic/stats", "GET", params); case 4: data = _context16.sent; return _context16.abrupt("return", data); case 6: case "end": return _context16.stop(); } } }, _callee16, this); })); function getTrafficStats(_x25, _x26, _x27) { return _ref16.apply(this, arguments); } return getTrafficStats; }() }, { key: "getDetectBreakdown", value: function () { var _ref17 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee17(start, end) { var data; return regeneratorRuntime.wrap(function _callee17$(_context17) { while (1) { switch (_context17.prev = _context17.next) { case 0: _context17.next = 2; return this._apiCall("insight/" + this._oid + "/detections/breakdown", "GET", { start: start, end: end }); case 2: data = _context17.sent; return _context17.abrupt("return", data); case 4: case "end": return _context17.stop(); } } }, _callee17, this); })); function getDetectBreakdown(_x28, _x29) { return _ref17.apply(this, arguments); } return getDetectBreakdown; }() }, { key: "getDetectStats", value: function () { var _ref18 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee18(start, end, sid) { var params, data; return regeneratorRuntime.wrap(function _callee18$(_context18) { while (1) { switch (_context18.prev = _context18.next) { case 0: params = { start: start, end: end }; if (sid) { params["sid"] = sid; } _context18.next = 4; return this._apiCall("insight/" + this._oid + "/detections/stats", "GET", params); case 4: data = _context18.sent; return _context18.abrupt("return", data); case 6: case "end": return _context18.stop(); } } }, _callee18, this); })); function getDetectStats(_x30, _x31, _x32) { return _ref18.apply(this, arguments); } return getDetectStats; }() }, { key: "getJobs", value: function () { var _ref19 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee19(params) { var _this2 = this; var data; return regeneratorRuntime.wrap(function _callee19$(_context19) { while (1) { switch (_context19.prev = _context19.next) { case 0: if (!params) { params = {}; } params["is_compressed"] = "true"; _context19.next = 4; return this._apiCall("job/" + this._oid, "GET", params); case 4: data = _context19.sent; _context19.next = 7; return this._unzip(Buffer.from(data.jobs, "base64")); case 7: data.jobs = _context19.sent; data.jobs = JSON.parse(data.jobs); return _context19.abrupt("return", Object.values(data.jobs).map(function (i) { return new Job(_this2, i); })); case 10: case "end": return _context19.stop(); } } }, _callee19, this); })); function getJobs(_x33) { return _ref19.apply(this, arguments); } return getJobs; }() }, { key: "getJob", value: function () { var _ref20 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee20(jid) { var data; return regeneratorRuntime.wrap(function _callee20$(_context20) { while (1) { switch (_context20.prev = _context20.next) { case 0: params["is_compressed"] = "true"; _context20.next = 3; return this._apiCall("job/" + this._oid + "/" + jid, "GET", {}); case 3: data = _context20.sent; _context20.next = 6; return this._unzip(Buffer.from(data.jobs, "base64")); case 6: data.job = _context20.sent; data.job = JSON.parse(data.job); return _context20.abrupt("return", new Job(this, data.job)); case 9: case "end": return _context20.stop(); } } }, _callee20, this); })); function getJob(_x34) { return _ref20.apply(this, arguments); } return getJob; }() }, { key: "replicantRequest", value: function () { var _ref21 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee21(replicantName, params, isSynchronous, timeout) { var data; return regeneratorRuntime.wrap(function _callee21$(_context21) { while (1) { switch (_context21.prev = _context21.next) { case 0: if (!timeout) { timeout = 30 * 1000; } _context21.next = 3; return this._apiCall("replicant/" + this._oid + "/" + replicantName, "POST", { request_data: btoa(JSON.stringify(params)), is_async: !isSynchronous }, false, false, timeout); case 3: data = _context21.sent; return _context21.abrupt("return", data); case 5: case "end": return _context21.stop(); } } }, _callee21, this); })); function replicantRequest(_x35, _x36, _x37, _x38) { return _ref21.apply(this, arguments); } return replicantRequest; }() }, { key: "getAvailableReplicants", value: function () { var _ref22 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee22() { var data; return regeneratorRuntime.wrap(function _callee22$(_context22) { while (1) { switch (_context22.prev = _context22.next) { case 0: _context22.next = 2; return this._apiCall("replicant/" + this._oid, "GET"); case 2: data = _context22.sent; return _context22.abrupt("return", data.replicants); case 4: case "end": return _context22.stop(); } } }, _callee22, this); })); function getAvailableReplicants() { return _ref22.apply(this, arguments); } return getAvailableReplicants; }() }, { key: "getOrgInfo", value: function () { var _ref23 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee23() { var data; return regeneratorRuntime.wrap(function _callee23$(_context23) { while (1) { switch (_context23.prev = _context23.next) { case 0: _context23.next = 2; return this._apiCall("orgs/" + this._oid, "GET"); case 2: data = _context23.sent; return _context23.abrupt("return", data); case 4: case "end": return _context23.stop(); } } }, _callee23, this); })); function getOrgInfo() { return _ref23.apply(this, arguments); } return getOrgInfo; }() }, { key: "getInsightLogs", value: function () { var _ref24 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee24(start, end, source, hint, cursor) { var params, data; return regeneratorRuntime.wrap(function _callee24$(_context24) { while (1) { switch (_context24.prev = _context24.next) { case 0: params = { start: start, end: end }; if (source) { params["source"] = source; } if (hint) { params["hint"] = hint; } if (cursor) { params["cursor"] = cursor; } _context24.next = 6; return this._apiCall("insight/" + this._oid + "/logs", "GET", params); case 6: data = _context24.sent; return _context24.abrupt("return", data); case 8: case "end": return _context24.stop(); } } }, _callee24, this); })); function getInsightLogs(_x39, _x40, _x41, _x42, _x43) { return _ref24.apply(this, arguments); } return getInsightLogs; }() }, { key: "getInsightLogPayload", value: function () { var _ref25 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee25(payloadID, records, with_raw) { var params, data; return regeneratorRuntime.wrap(function _callee25$(_context25) { while (1) { switch (_context25.prev = _context25.next) { case 0: params = { records: records, with_raw: with_raw ? 'on' : 'off', is_compressed: 'true' }; _context25.next = 3; return this._apiCall("insight/" + this._oid + "/logs/payloads/" + payloadID, "GET", params, false, false, 60 * 1000); case 3: data = _context25.sent; _context25.next = 6; return this._unzip(Buffer.from(data.logs, "base64")); case 6: data.logs = _context25.sent; data.logs = JSON.parse(data.logs); return _context25.abrupt("return", data.logs); case 9: case "end": return _context25.stop(); } } }, _callee25, this); })); function getInsightLogPayload(_x44, _x45, _x46) { return _ref25.apply(this, arguments); } return getInsightLogPayload; }() }, { key: "getInsightLogOriginal", value: function () { var _ref26 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee26(payloadID, params) { var data; return regeneratorRuntime.wrap(function _callee26$(_context26) { while (1) { switch (_context26.prev = _context26.next) { case 0: if (!params) { params = {}; } _context26.next = 3; return this._apiCall("insight/" + this._oid + "/logs/originals/" + payloadID, "GET", params, false, false, 60 * 1000); case 3: data = _context26.sent; if (!data.payload) { _context26.next = 10; break; } _context26.next = 7; return this._unzip(Buffer.from(data.payload, "base64"), true); case 7: data.payload = _context26.sent; _context26.next = 11; break; case 10: data.payload = null; case 11: return _context26.abrupt("return", data); case 12: case "end": return _context26.stop(); } } }, _callee26, this); })); function getInsightLogOriginal(_x47, _x48) { return _ref26.apply(this, arguments); } return getInsightLogOriginal; }() }, { key: "getInsightLogFlow", value: function () { var _ref27 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee27(flowID, start, end, with_raw) { var params, data; return regeneratorRuntime.wrap(function _callee27$(_context27) { while (1) { switch (_context27.prev = _context27.next) { case 0: params = { start: start, end: end, with_raw: with_raw ? 'on' : 'off', is_compressed: 'true' }; _context27.next = 3; return this._apiCall("insight/" + this._oid + "/logs/flows/" + flowID, "GET", params); case 3: data = _context27.sent; _context27.next = 6; return this._unzip(Buffer.from(data.flows, "base64")); case 6: data.flows = _context27.sent; data.flows = JSON.parse(data.flows); return _context27.abrupt("return", data.flows); case 9: case "end": return _context27.stop(); } } }, _callee27, this); })); function getInsightLogFlow(_x49, _x50, _x51, _x52) { return _ref27.apply(this, arguments); } return getInsightLogFlow; }() }, { key: "getIngestionKeys", value: function () { var _ref28 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee28() { var data; return regeneratorRuntime.wrap(function _callee28$(_context28) { while (1) { switch (_context28.prev = _context28.next) { case 0: _context28.next = 2; return this._apiCall("insight/" + this._oid + "/ingestion_keys", "GET", {}); case 2: data = _context28.sent; return _context28.abrupt("return", data.keys); case 4: case "end": return _context28.stop(); } } }, _callee28, this); })); function getIngestionKeys() { return _ref28.apply(this, arguments); } return getIngestionKeys; }() }, { key: "setIngestionKey", value: function () { var _ref29 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee29(name) { var data; return regeneratorRuntime.wrap(function _callee29$(_context29) { while (1) { switch (_context29.prev = _context29.next) { case 0: _context29.next = 2; return this._apiCall("insight/" + this._oid + "/ingestion_keys", "POST", { name: name }); case 2: data = _context29.sent; return _context29.abrupt("return", data); case 4: case "end": return _context29.stop(); } } }, _callee29, this); })); function setIngestionKey(_x53) { return _ref29.apply(this, arguments); } return setIngestionKey; }() }, { key: "delIngestionKey", value: function () { var _ref30 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee30(name) { var data; return regeneratorRuntime.wrap(function _callee30$(_context30) { while (1) { switch (_context30.prev = _context30.next) { case 0: _context30.next = 2; return this._apiCall("insight/" + this._oid + "/ingestion_keys", "DELETE", { name: name }); case 2: data = _context30.sent; return _context30.abrupt("return", data); case 4: case "end": return _context30.stop(); } } }, _callee30, this); })); function delIngestionKey(_x54) { return _ref30.apply(this, arguments); } return delIngestionKey; }() }, { key: "getUsage", value: function () { var _ref31 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee31() { var data; return regeneratorRuntime.wrap(function _callee31$(_context31) { while (1) { switch (_context31.prev = _context31.next) { case 0: _context31.next = 2; return this._apiCall("usage/" + this._oid, "GET", {}, false, false, 20 * 1000); case 2: data = _context31.sent; return _context31.abrupt("return", data.usage); case 4: case "end": return _context31.stop(); } } }, _callee31, this); })); function getUsage() { return _ref31.apply(this, arguments); } return getUsage; }() }, { key: "getDrRules", value: function () { var _ref32 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee32(namespace) { var req, data; return regeneratorRuntime.wrap(function _callee32$(_context32) { while (1) { switch (_context32.prev = _context32.next) { case 0: req = {}; if (namespace) { req['namespace'] = namespace; } _context32.next = 4; return this._apiCall("rules/" + this._oid, "GET", req); case 4: data = _context32.sent; return _context32.abrupt("return", data); case 6: case "end": return _context32.stop(); } } }, _callee32, this); })); function getDrRules(_x55) { return _ref32.apply(this, arguments); } return getDrRules; }() }, { key: "getFpRules", value: function () { var _ref33 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee33() { var req, data; return regeneratorRuntime.wrap(function _callee33$(_context33) { while (1) { switch (_context33.prev = _context33.next) { case 0: req = {}; _context33.next = 3; return this._apiCall("fp/" + this._oid, "GET", req); case 3: data = _context33.sent; return _context33.abrupt("return", data); case 5: case "end": return _context33.stop(); } } }, _callee33, this); })); function getFpRules() { return _ref33.apply(this, arguments); } return getFpRules; }() }, { key: "getObjectsTimeline", value: function () { var _ref34 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee34(objects, params) { var data; return regeneratorRuntime.wrap(function _callee34$(_context34) { while (1) { switch (_context34.prev = _context34.next) { case 0: if (!params) { params = {}; } params["is_compressed"] = "true"; params["objects"] = JSON.stringify(objects); _context34.next = 5; return this._apiCall("insight/" + this._oid + "/objects_timeline", "POST", params); case 5: data = _context34.sent; _context34.next = 8; return this._unzip(Buffer.from(data.timeline, "base64")); case 8: data.timeline = _context34.sent; data.timeline = JSON.parse(data.timeline); _context34.next = 12; return this._unzip(Buffer.from(data.prevalence, "base64")); case 12: data.prevalence = _context34.sent; data.prevalence = JSON.parse(data.prevalence); return _context34.abrupt("return", data); case 15: case "end": return _context34.stop(); } } }, _callee34, this); })); function getObjectsTimeline(_x56, _x57) { return _ref34.apply(this, arguments); } return getObjectsTimeline; }() }, { key: "getObjectUsage", value: function () { var _ref35 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee35(objType, objName, startTime, endTime, params) { var data; return regeneratorRuntime.wrap(function _callee35$(_context35) { while (1) { switch (_context35.prev = _context35.next) { case 0: if (!params) { params = {}; } params["is_compressed"] = "true"; params["name"] = objName; params["start"] = startTime; params["end"] = endTime; _context35.next = 7; return this._apiCall("insight/" + this._oid + "/object_usage/" + objType, "GET", params); case 7: data = _context35.sent; _context35.next = 10; return this._unzip(Buffer.from(data.usage, "base64")); case 10: data.usage = _context35.sent; data.usage = JSON.parse(data.usage); _context35.next = 14; return this._unzip(Buffer.from(data.logs, "base64")); case 14: data.logs = _context35.sent; data.logs = JSON.parse(data.logs); return _context35.abrupt("return", data); case 17: case "end": return _context35.stop(); } } }, _callee35, this); })); function getObjectUsage(_x58, _x59, _x60, _x61, _x62) { return _ref35.apply(this, arguments); } return getObjectUsage; }() }, { key: "whoAmI", value: function () { var _ref36 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee36() { var data; return regeneratorRuntime.wrap(function _callee36$(_context36) { while (1) { switch (_context36.prev = _context36.next) { case 0: _context36.next = 2; return this._apiCall("who", "GET", {}, false, false, null, ROOT_URL); case 2: data = _context36.sent; return _context36.abrupt("return", data); case 4: case "end": return _context36.stop(); } } }, _callee36, this); })); function whoAmI() { return _ref36.apply(this, arguments); } return whoAmI; }() }, { key: "getSensorsOnline", value: function () { var _ref37 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee37(sids) { var params, data; return regeneratorRuntime.wrap(function _callee37$(_context37) { while (1) { switch (_context37.prev = _context37.next) { case 0: params = { 'sids': sids }; _context37.next = 3; return this._apiCall("online/" + this._oid, "POST", params); case 3: data = _context37.sent; return _context37.abrupt("return", data); case 5: case "end": return _context37.stop(); } } }, _callee37, this); })); function getSensorsOnline(_x63) { return _ref37.apply(this, arguments); } return getSensorsOnline; }() }]); return Manager; }(); module.exports = Manager;