|
|
@ -26,14 +26,18 @@ policyModule = function () {
|
|
|
|
var publicMethods = {};
|
|
|
|
var publicMethods = {};
|
|
|
|
var privateMethods = {};
|
|
|
|
var privateMethods = {};
|
|
|
|
|
|
|
|
|
|
|
|
publicMethods.addPolicy = function (name, deviceType, policyDefinition, policyDescription) {
|
|
|
|
publicMethods.addPolicy = function (policyName, deviceType, policyDefinition, policyDescription) {
|
|
|
|
|
|
|
|
if(policyName && deviceType){
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var carbonModule = require("carbon");
|
|
|
|
var carbonModule = require("carbon");
|
|
|
|
var carbonServer = application.get("carbonServer");
|
|
|
|
var carbonServer = application.get("carbonServer");
|
|
|
|
var options = {system: true};
|
|
|
|
var options = {system: true};
|
|
|
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
|
|
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
|
|
|
|
|
|
|
|
|
|
|
resource = {
|
|
|
|
var resource = {
|
|
|
|
name: name,
|
|
|
|
name: policyName,
|
|
|
|
mediaType: 'text/plain',
|
|
|
|
mediaType: 'text/plain',
|
|
|
|
content: policyDefinition,
|
|
|
|
content: policyDefinition,
|
|
|
|
description: policyDescription
|
|
|
|
description: policyDescription
|
|
|
@ -42,11 +46,11 @@ policyModule = function () {
|
|
|
|
if (carbonUser) {
|
|
|
|
if (carbonUser) {
|
|
|
|
options.tenantId = carbonUser.tenantId;
|
|
|
|
options.tenantId = carbonUser.tenantId;
|
|
|
|
var registry = new carbonModule.registry.Registry(carbonServer, options);
|
|
|
|
var registry = new carbonModule.registry.Registry(carbonServer, options);
|
|
|
|
log.info("########### Policy name : " + name);
|
|
|
|
log.info("########### Policy name : " + policyName);
|
|
|
|
log.info("########### Policy type : " + deviceType);
|
|
|
|
log.info("########### Policy type : " + deviceType);
|
|
|
|
log.info("########### Policy Declaration : " + policyDefinition);
|
|
|
|
log.info("########### Policy Declaration : " + policyDefinition);
|
|
|
|
log.info("########### Policy policyDescription: " + policyDescription);
|
|
|
|
log.info("########### Policy policyDescription: " + policyDescription);
|
|
|
|
registry.put(constants.POLICY_REGISTRY_PATH + deviceType + "/" + name, resource);
|
|
|
|
registry.put(constants.POLICY_REGISTRY_PATH + deviceType + "/" + policyName, resource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var mqttsenderClass = Packages.org.wso2.device.mgt.mqtt.policy.push.MqttPush;
|
|
|
|
var mqttsenderClass = Packages.org.wso2.device.mgt.mqtt.policy.push.MqttPush;
|
|
|
@ -55,6 +59,7 @@ policyModule = function () {
|
|
|
|
var result = mqttsender.pushToMQTT("/iot/policymgt/govern", policyDefinition, "tcp://10.100.0.104:1883", "Raspberry-Policy-sender");
|
|
|
|
var result = mqttsender.pushToMQTT("/iot/policymgt/govern", policyDefinition, "tcp://10.100.0.104:1883", "Raspberry-Policy-sender");
|
|
|
|
|
|
|
|
|
|
|
|
mqttsender = null;
|
|
|
|
mqttsender = null;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
publicMethods.getPolicies = function () {
|
|
|
|
publicMethods.getPolicies = function () {
|
|
|
|