Skip to content

Commit

Permalink
Changes to SLA format and grant app permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Toshbrown committed Mar 8, 2017
1 parent 641491d commit fc1b905
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"jsonfile": "^2.4.0",
"material-design-lite": "^1.2.1",
"mocha": "^3.1.2",
"modclean": "",
"nedb": "^1.8.0",
"node-forge": "^0.6.45",
"pug": "^2.0.0-beta6",
Expand All @@ -46,7 +47,7 @@
"should": "^11.1.1",
"socket.io": "^1.5.0",
"supertest": "^2.0.1",
"modclean": ""
"url": "^0.11.0"
},
"devDependencies": {
"node-sass": "^3.10.0",
Expand Down
55 changes: 55 additions & 0 deletions src/container-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var os = require('os');
var crypto = require('crypto');
var request = require('request');
var https = require('https');
var url = require('url');

var db = require('./include/container-manager-db.js');
var dockerHelper = require('./include/container-manager-docker-helper.js');
Expand Down Expand Up @@ -808,6 +809,60 @@ let launchContainer = function (containerSLA) {
'Links': [arbiterName]
}
};

//set read permissions from the sla for DATASOURCES. Limit this to Apps only??
var readProms = [];
if(containerSLA.datasources) {
for(var allowedDatasource of containerSLA.datasources) {

var datasourceEndpoint = url.parse(allowedDatasource.endpoint);
var datasourceName = allowedDatasource.datasource;

readProms.push(updateContainerPermissions({
name: containerSLA.localContainerName,
route: {target:datasourceEndpoint.hostname, path: '/'+datasourceName, method:'GET'}
}));
console.log("read api",{
name: containerSLA.localContainerName,
route: {target:datasourceEndpoint.hostname, path: '/'+datasourceName, method:'GET'}
});

readProms.push(updateContainerPermissions({
name: containerSLA.localContainerName,
route: {target:datasourceEndpoint.hostname, path: '/'+datasourceName+'/*', method:'GET'}
}));

readProms.push(updateContainerPermissions({
name: containerSLA.localContainerName,
route: {target:datasourceEndpoint.hostname, path: '/ws' , method:'GET'}
}));

console.log("/ws",{
name: containerSLA.localContainerName,
route: {target:datasourceEndpoint.hostname, path: '/ws' , method:'GET'}
});

readProms.push(updateContainerPermissions({
name: containerSLA.localContainerName,
route: {target:datasourceEndpoint.hostname, path: '/sub/' + datasourceName + '/*' , method:'GET'}
}));

console.log("/sub",{
name: containerSLA.localContainerName,
route: {target:datasourceEndpoint.hostname, path: '/sub/' + datasourceName + '/*' , method:'GET'}
});
}

Promise.all(readProms)
.then(()=>{
console.log('[Added read permissions for]:' + containerSLA.localContainerName);
})
.catch((error)=>{
//TODO sort out nested promises and think about stopping the install if this fails
console.log('[ERROR Adding read permissions for]:' + containerSLA.localContainerName, error);
});
}

let launched = [];

return new Promise((resolve, reject) => {
Expand Down
9 changes: 5 additions & 4 deletions src/www/install.pug
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ html
if ('items' in data) {
for (var item of data.items) {
var sensor = {};
sensor.endpoint = url;
sensor.endpoint = item.href;
if ('item-metadata' in item) {
for (var metadata of item['item-metadata']) {
if (metadata.rel in mappings) {
Expand Down Expand Up @@ -105,10 +105,11 @@ html
for (var sensor of sensors) {
if (sensor.index === sensor_index) {
datasource.endpoint = sensor.endpoint;
datasource.sensor_id = sensor.id;
datasource.sensor = sensor.description;
datasource.datasource = sensor.id;
datasource.description = sensor.description;
datasource.location = sensor.location || "";
if(sensor.location) {
datasource.sensor += ", " + sensor.location
datasource.description += ", " + sensor.location
}
datasource.hypercat = sensor.hypercat;
update();
Expand Down
2 changes: 1 addition & 1 deletion src/www/templates/app-manifest.pug
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ div
ul.mdl-menu.mdl-menu--bottom-left.mdl-js-menu.mdl-js-ripple-effect(for='datasource_' + datasource.clientid)
each sensor in getSensors(datasource.type)
li.mdl-menu__item(onclick='selectSensor("' + datasource.clientid + '",' + sensor.index + ')')
= sensor.description + ', ' + sensor.location
= sensor.description + ', ' + (sensor.location || "")
else
li.mdl-menu__item(disabled)
| No sensors found
Expand Down

0 comments on commit fc1b905

Please sign in to comment.