Update all nodes to credentials system and auth middleware

This commit is contained in:
Nick O'Leary
2015-02-06 21:10:14 +00:00
parent f4fdebfba5
commit 08791f1914
29 changed files with 177 additions and 783 deletions

View File

@@ -1,6 +1,6 @@
<!--
Copyright 2014 Charalampos Doukas, @BuildingIoT
Copyright 2014, 2015 Charalampos Doukas, @BuildingIoT
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@
</div>
<div class="form-row">
<label for="node-input-appkey_sub"><i class="fa fa-lock"></i> App Key</label>
<input type="text" id="node-input-appkey_sub" placeholder="key">
<input type="text" id="node-input-pusherappkey_sub" placeholder="key">
</div>
<div class="form-row">
@@ -51,6 +51,9 @@
channel: {value:"", required:true},
eventname: {value:"", required:true}
},
credentials: {
pusherappkey_sub: "text"
},
inputs:0, // set the number of inputs - only 0 or 1
outputs:1, // set the number of outputs - 0 to n
icon: "pusher.png", // set the icon (held in public/icons)
@@ -59,31 +62,6 @@
},
labelStyle: function() { // sets the class to apply to the label
return this.name?"node_label_italic":"";
},
oneditsave: function() {
var credentials = {};
var newAppKey_sub = $('#node-input-appkey_sub').val();
credentials.pusherappkey_sub = newAppKey_sub;
$.ajax({
url: 'pusher/'+this.id,
type: 'POST',
data: credentials,
success: function(result){}
});
},
oneditprepare: function() {
$.getJSON('pusher/'+this.id,function(data) {
if (data.pusherappkey_sub) {
$('#node-input-appkey_sub').val(data.pusherappkey_sub);
}
});
},
ondelete: function() {
$.ajax({
url: 'pusher/'+this.id,
type: 'DELETE',
success: function(result) {}
});
}
});
</script>
@@ -101,17 +79,17 @@
<div class="form-row">
<label for="node-input-appid"><i class="fa fa-tag"></i> App ID</label>
<input type="text" id="node-input-appid" placeholder="app_id">
<input type="text" id="node-input-pusherappid" placeholder="app_id">
</div>
<div class="form-row">
<label for="node-input-appkey"><i class="fa fa-lock"></i> App Key</label>
<input type="text" id="node-input-appkey" placeholder="key">
<input type="text" id="node-input-pusherappkey" placeholder="key">
</div>
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-asterisk"></i> App Secret</label>
<input type="password" id="node-input-appsecret" placeholder="secret">
<input type="password" id="node-input-pusherappsecret" placeholder="secret">
</div>
<div class="form-row">
@@ -135,6 +113,11 @@
channel: {value:"", required:true},
eventname: {value:"", required:true}
},
credentials: {
pusherappid: {type:"text"},
pusherappkey: {type:"text"},
pusherappsecret: {type:"password"}
},
inputs:1, // set the number of inputs - only 0 or 1
outputs:0, // set the number of outputs - 0 to n
icon: "pusher.png", // set the icon (held in public/icons)
@@ -144,41 +127,6 @@
},
labelStyle: function() { // sets the class to apply to the label
return this.name?"node_label_italic":"";
},
oneditsave: function() {
var credentials = {};
var newAppID = $('#node-input-appid').val();
var newAppKey = $('#node-input-appkey').val();
var newAppSecret = $('#node-input-appsecret').val();
credentials.pusherappid = newAppID;
credentials.pusherappkey = newAppKey;
credentials.pusherappsecret = newAppSecret;
$.ajax({
url: 'pusher/'+this.id,
type: 'POST',
data: credentials,
success: function(result){}
});
},
oneditprepare: function() {
$.getJSON('pusher/'+this.id,function(data) {
if (data.pusherappid) {
$('#node-input-appid').val(data.pusherappid);
}
if (data.pusherappkey) {
$('#node-input-appkey').val(data.pusherappkey);
}
if (data.pusherappsecret) {
$('#node-input-appsecret').val(data.pusherappsecret);
}
});
},
ondelete: function() {
$.ajax({
url: 'pusher/'+this.id,
type: 'DELETE',
success: function(result) {}
});
}
});
</script>

View File

@@ -3,7 +3,7 @@
* Subscription module for the Pusher service (www.pusher.com)
* Requires 'pusher' and 'pusher-client' modules.
*
* Copyright 2014 Charalampos Doukas, @BuildingIoT
* Copyright 2014, 2015 Charalampos Doukas, @BuildingIoT
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ module.exports = function(RED) {
RED.nodes.createNode(this,n);
var node = this;
var credentials = RED.nodes.getCredentials(n.id);
var credentials = this.credentials;
if ((credentials) && (credentials.hasOwnProperty("pusherappkey_sub"))) { this.appkey = credentials.pusherappkey_sub; }
else { this.error("No Pusher app key set for input node"); }
@@ -61,7 +61,7 @@ module.exports = function(RED) {
var node = this;
var credentials = RED.nodes.getCredentials(n.id);
var credentials = this.credentials;
if ((credentials) && (credentials.hasOwnProperty("pusherappid"))) { this.appid = credentials.pusherappid; }
else { this.error("No Pusher api token set"); }
@@ -99,59 +99,16 @@ module.exports = function(RED) {
node.log("Error: "+err);
};
RED.nodes.registerType("pusher in",PusherNode);
RED.nodes.registerType("pusher out",PusherNodeSend);
var querystring = require('querystring');
RED.httpAdmin.get('/pusher/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({pusherappid:credentials.pusherappid,pusherappsecret:credentials.pusherappsecret, pusherappkey:credentials.pusherappkey, pusherappkey_sub:credentials.pusherappkey_sub}));
} else {
res.send(JSON.stringify({}));
RED.nodes.registerType("pusher in",PusherNode,{
credentials: {
pusherappkey_sub: "text"
}
});
RED.nodes.registerType("pusher out",PusherNodeSend,{
credentials: {
pusherappid: {type:"text"},
pusherappkey: {type:"text"},
pusherappsecret: {type:"password"}
}
});
RED.httpAdmin.delete('/pusher/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
RED.httpAdmin.post('/pusher/:id',function(req,res) {
var body = "";
req.on('data', function(chunk) {
body+=chunk;
});
req.on('end', function(){
var newCreds = querystring.parse(body);
var credentials = RED.nodes.getCredentials(req.params.id)||{};
if (newCreds.pusherappid === null || newCreds.pusherappid === "") {
delete credentials.pusherappid;
} else {
credentials.pusherappid = newCreds.pusherappid;
}
if (newCreds.pusherappkey === "") {
delete credentials.pusherappkey;
} else {
credentials.pusherappkey = newCreds.pusherappkey||credentials.pusherappkey;
}
if (newCreds.pusherappsecret === "") {
delete credentials.pusherappsecret;
} else {
credentials.pusherappsecret = newCreds.pusherappsecret||credentials.pusherappsecret;
}
if (newCreds.pusherappkey_sub === "") {
delete credentials.pusherappkey_sub;
} else {
credentials.pusherappkey_sub = newCreds.pusherappkey_sub||credentials.pusherappkey_sub;
}
RED.nodes.addCredentials(req.params.id,credentials);
res.send(200);
});
});
}