@ale-de/cirrus-node
Version:
Node to consume REST API of the Alcatel-Lucent Enterprise Cirrus Cloud Network Manager
286 lines (247 loc) • 8.25 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var rxjs = require('rxjs');
var operators = require('rxjs/internal/operators');
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);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
//import {inspect} from 'util'
var axios =
/*#__PURE__*/
require('axios')["default"];
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; //needed to get around UNABLE_TO_VERIFY_LEAF_SIGNATURE error returned by OV2500 (not Cirrus): Certificate issue
exports.CirrusAPI =
/*#__PURE__*/
function () {
function CirrusAPI(host) {
// @ts-ignore
this.token = '';
this.cookie = '';
this.cirrus = axios.create({
baseURL: "https://" + host + "/api/",
timeout: 20000,
rejectUnauthorized: false
});
}
var _proto = CirrusAPI.prototype;
_proto.login = function login(data) {
var _this = this;
return new Promise(function (resolve, reject) {
_this.cirrus.post('login', {
userName: data.username,
password: data.password
}, {
headers: _this.headers
}).then(function (response) {
_this.token = response.data.accessToken;
_this.cookie = response.headers['set-cookie'];
resolve(true);
})["catch"](function (err) {
console.log("Got login failed for " + data.username, err);
reject(false);
});
});
};
_proto.about = function about() {
var _this2 = this;
return new Promise(function (resolve, reject) {
_this2.cirrus.get('about', {
headers: _this2.headers
}).then(function (response) {
var about = response.data;
resolve(about);
})["catch"](function (err) {
//console.log(err);
reject(err);
});
});
};
_proto.getIotInventoryWithRetry = function getIotInventoryWithRetry() {
var _this3 = this;
return new rxjs.Observable(function (observable) {
_this3.cirrus.post('iot/inventory', new OV_getIotInventory(), {
headers: _this3.headers
}).then(function (resultSet) {
var cirrusResponse = resultSet.data;
if (cirrusResponse.response.hasOwnProperty('ioTInventoryVOs')) {
observable.next(cirrusResponse.response.ioTInventoryVOs);
} else observable.error("getIotInventoryWithRetry Bad response format");
observable.complete();
})["catch"](function (err) {
console.log("Got getIotInventoryWithRetry error", err);
observable.error(err);
})["finally"](function () {});
}).pipe(operators.retry(3));
};
_proto.getDevices = function getDevices() {
var _this4 = this;
return new Promise(function (resolve, reject) {
_this4.cirrus.get('devices?fieldSetName=discovery', {
headers: _this4.headers
}).then(function (resultSet) {
var response = resultSet.data;
var devices = response.response; //console.log("getDevices", devices);
resolve(devices);
})["catch"](function (err) {
reject(err);
});
});
};
_proto.getSsid = function getSsid() {
var _this5 = this;
return new Promise(function (resolve, reject) {
_this5.cirrus.get('ag/uatemplate/SSIDSimplification', {
headers: _this5.headers
}).then(function (resultSet) {
var response = resultSet.data;
var ssid = response.response;
resolve(ssid);
})["catch"](function (err) {
reject(err);
});
});
};
_proto.updateSsidStatus = function updateSsidStatus(ssidInstanceId, status) {
var _this6 = this;
return new Promise(function (resolve, reject) {
_this6.cirrus.put("ag/ssid/" + (status ? 'enable' : 'disable'), new OV_updateSsidStatus(ssidInstanceId), {
headers: _this6.headers
}).then(function (resultSet) {
resolve(resultSet.data);
})["catch"](function (err) {
console.log("Got updateSsidStatus error", err);
reject(err);
})["finally"](function () {});
});
};
_proto.addVlan = function addVlan(deviceId, vlan) {
var _this7 = this;
console.log("Adding VLAN " + vlan + " for " + deviceId);
return new Promise(function (resolve, reject) {
_this7.cirrus.post("vlanservice/devices/vlans/", {
data: new OV_addVlanData(deviceId, vlan)
}, {
headers: _this7.headers
}).then(function (resultSet) {
resolve(resultSet.data);
})["catch"](function (err) {
console.log("Got addVlan error", err);
reject(err);
})["finally"](function () {});
});
};
_proto.deleteVlan = function deleteVlan(deviceId, vlan) {
var _this8 = this;
return new Promise(function (resolve, reject) {
_this8.cirrus["delete"]("vlanservice/devices/vlans/", {
data: {
data: new OV_deleteVlanData(deviceId, vlan)
},
headers: _this8.headers
}).then(function (resultSet) {
resolve(resultSet.data);
})["catch"](function (err) {
console.log("Got addVlan error", err);
reject(err);
})["finally"](function () {});
});
};
_createClass(CirrusAPI, [{
key: "version",
get: function get() {
return 'Version cirrus-node : 0.1.29';
}
}, {
key: "headers",
get: function get() {
return {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Ov-App-Version': '4.4R2',
'Cookie': this.cookie.toString()
};
}
}]);
return CirrusAPI;
}();
(function (CirrusAPI) {
var ResultResponseType;
(function (ResultResponseType) {
ResultResponseType["IotInventoryResponse"] = "IotInventoryResponse";
})(ResultResponseType || (ResultResponseType = {}));
var ResponseType;
(function (ResponseType) {
ResponseType["RESPONSE_SYNCHRONOUS"] = "RESPONSE_SYNCHRONOUS";
ResponseType["ArrayList"] = "ArrayList";
})(ResponseType || (ResponseType = {}));
})(exports.CirrusAPI || (exports.CirrusAPI = {}));
var OV_updateSsidStatus = function OV_updateSsidStatus(ssidInstanceId) {
this.UnifiedProfileAssignRequestObject = {
documentIds: [ssidInstanceId]
};
};
var OV_getIotInventory = function OV_getIotInventory() {
this.type = "IotInventoryRequest";
this.endpointStatus = "All";
this.filterBy = "ALL";
this.macAddresses = [];
this.categories = [];
this.unps = [];
this.ssids = [];
this.deviceMap = {};
this.apGroups = null;
this.mapIds = null;
this.timeRange = null;
this.pageSize = 1000;
this.pageNumber = 1;
this.debugMode = false;
this.latestRecords = true;
};
var OV_addVlanData = function OV_addVlanData(deviceId, vlan) {
this["vlanNumber"] = [];
this["unTaggedPortTemplate"] = [];
this["taggedPortTemplate"] = [];
this["overWrite"] = false;
this["vlanTableInfo"] = [];
this["defaultVlanNumber"] = '';
this.vlanNumber.push(vlan);
this.vlanTableInfo.push(new VlanTableInfo(deviceId));
};
var OV_deleteVlanData = function OV_deleteVlanData(deviceId, vlan) {
this["deviceInfos"] = [];
this["vlanNumber"] = 0;
this["vlanTableInfo"] = [];
this.deviceInfos.push({
"deviceId": deviceId
});
this.vlanTableInfo.push({
"vlanInfo": {
"number": vlan
}
});
};
var VlanTableInfo = function VlanTableInfo(deviceId) {
this["deviceId"] = '';
this["useTaggedPortTemplate"] = true;
this["useUnTaggedPortTemplate"] = true;
this["tagged"] = [];
this.deviceId = deviceId;
};
/*
var c = new CirrusAPI("antwerp.ov.ovcirrus.com");
c.login({username: 'devrard', password: "aleCIRRUS#1"}).then(()=>{
//c.getIotInventoryWithRetry().subscribe((data)=>{console.log("Retrieved iot list:",data);})
//c.getDevices().then(data=>{console.log("devices", data)})
})*/
//# sourceMappingURL=cirrus-node.cjs.development.js.map