|
|
|
@ -26,14 +26,18 @@ policyModule = function () {
|
|
|
|
|
var publicMethods = {};
|
|
|
|
|
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 carbonServer = application.get("carbonServer");
|
|
|
|
|
var options = {system: true};
|
|
|
|
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
|
|
|
|
|
|
|
|
|
resource = {
|
|
|
|
|
name: name,
|
|
|
|
|
var resource = {
|
|
|
|
|
name: policyName,
|
|
|
|
|
mediaType: 'text/plain',
|
|
|
|
|
content: policyDefinition,
|
|
|
|
|
description: policyDescription
|
|
|
|
@ -42,11 +46,11 @@ policyModule = function () {
|
|
|
|
|
if (carbonUser) {
|
|
|
|
|
options.tenantId = carbonUser.tenantId;
|
|
|
|
|
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 Declaration : " + policyDefinition);
|
|
|
|
|
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;
|
|
|
|
@ -55,6 +59,7 @@ policyModule = function () {
|
|
|
|
|
var result = mqttsender.pushToMQTT("/iot/policymgt/govern", policyDefinition, "tcp://10.100.0.104:1883", "Raspberry-Policy-sender");
|
|
|
|
|
|
|
|
|
|
mqttsender = null;
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
publicMethods.getPolicies = function () {
|
|
|
|
|