UNPKG

@ale-de/cirrus-node

Version:

Node to consume REST API of the Alcatel-Lucent Enterprise Cirrus Cloud Network Manager

3 lines (2 loc) 4.19 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t,n=require("rxjs"),r=require("rxjs/internal/operators"),i=require("axios").default;process.env.NODE_TLS_REJECT_UNAUTHORIZED="0",exports.CirrusAPI=function(){function e(e){this.token="",this.cookie="",this.cirrus=i.create({baseURL:"https://"+e+"/api/",timeout:2e4,rejectUnauthorized:!1})}var t,c=e.prototype;return c.login=function(e){var t=this;return new Promise((function(n,r){t.cirrus.post("login",{userName:e.username,password:e.password},{headers:t.headers}).then((function(e){t.token=e.data.accessToken,t.cookie=e.headers["set-cookie"],n(!0)})).catch((function(t){console.log("Got login failed for "+e.username,t),r(!1)}))}))},c.about=function(){var e=this;return new Promise((function(t,n){e.cirrus.get("about",{headers:e.headers}).then((function(e){t(e.data)})).catch((function(e){n(e)}))}))},c.getIotInventoryWithRetry=function(){var e=this;return new n.Observable((function(t){e.cirrus.post("iot/inventory",new s,{headers:e.headers}).then((function(e){var n=e.data;n.response.hasOwnProperty("ioTInventoryVOs")?t.next(n.response.ioTInventoryVOs):t.error("getIotInventoryWithRetry Bad response format"),t.complete()})).catch((function(e){console.log("Got getIotInventoryWithRetry error",e),t.error(e)})).finally((function(){}))})).pipe(r.retry(3))},c.getDevices=function(){var e=this;return new Promise((function(t,n){e.cirrus.get("devices?fieldSetName=discovery",{headers:e.headers}).then((function(e){t(e.data.response)})).catch((function(e){n(e)}))}))},c.getSsid=function(){var e=this;return new Promise((function(t,n){e.cirrus.get("ag/uatemplate/SSIDSimplification",{headers:e.headers}).then((function(e){t(e.data.response)})).catch((function(e){n(e)}))}))},c.updateSsidStatus=function(e,t){var n=this;return new Promise((function(r,i){n.cirrus.put("ag/ssid/"+(t?"enable":"disable"),new o(e),{headers:n.headers}).then((function(e){r(e.data)})).catch((function(e){console.log("Got updateSsidStatus error",e),i(e)})).finally((function(){}))}))},c.addVlan=function(e,t){var n=this;return console.log("Adding VLAN "+t+" for "+e),new Promise((function(r,i){n.cirrus.post("vlanservice/devices/vlans/",{data:new a(e,t)},{headers:n.headers}).then((function(e){r(e.data)})).catch((function(e){console.log("Got addVlan error",e),i(e)})).finally((function(){}))}))},c.deleteVlan=function(e,t){var n=this;return new Promise((function(r,i){n.cirrus.delete("vlanservice/devices/vlans/",{data:{data:new u(e,t)},headers:n.headers}).then((function(e){r(e.data)})).catch((function(e){console.log("Got addVlan error",e),i(e)})).finally((function(){}))}))},(t=[{key:"version",get:function(){return"Version cirrus-node : 0.1.29"}},{key:"headers",get:function(){return{"Content-Type":"application/json",Accept:"application/json","Ov-App-Version":"4.4R2",Cookie:this.cookie.toString()}}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(e.prototype,t),e}(),exports.CirrusAPI||(exports.CirrusAPI={}),function(e){e.IotInventoryResponse="IotInventoryResponse"}(e||(e={})),function(e){e.RESPONSE_SYNCHRONOUS="RESPONSE_SYNCHRONOUS",e.ArrayList="ArrayList"}(t||(t={}));var o=function(e){this.UnifiedProfileAssignRequestObject={documentIds:[e]}},s=function(){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=1e3,this.pageNumber=1,this.debugMode=!1,this.latestRecords=!0},a=function(e,t){this.vlanNumber=[],this.unTaggedPortTemplate=[],this.taggedPortTemplate=[],this.overWrite=!1,this.vlanTableInfo=[],this.defaultVlanNumber="",this.vlanNumber.push(t),this.vlanTableInfo.push(new c(e))},u=function(e,t){this.deviceInfos=[],this.vlanNumber=0,this.vlanTableInfo=[],this.deviceInfos.push({deviceId:e}),this.vlanTableInfo.push({vlanInfo:{number:t}})},c=function(e){this.deviceId="",this.useTaggedPortTemplate=!0,this.useUnTaggedPortTemplate=!0,this.tagged=[],this.deviceId=e}; //# sourceMappingURL=cirrus-node.cjs.production.min.js.map