From fff55bb9d5921432d81405b9488606e9204f204c Mon Sep 17 00:00:00 2001 From: Ben Ariss Date: Thu, 30 Nov 2017 11:50:04 +0000 Subject: [PATCH] Added functionality to allow the credentials to optionally be passed in as part of the msg rather than defined in the configuration node. This allows them to be managed externally to the flow if required. --- README.md | 3 ++- connection-config.html | 16 ++++++++-------- dml.js | 16 ++++++++++++++++ package.json | 2 +- soql.js | 16 ++++++++++++++++ sosl.js | 16 ++++++++++++++++ streaming.js | 16 ++++++++++++++++ 7 files changed, 75 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 09d08bc..48162a1 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,8 @@ npm install node-red-contrib-salesforce ## Usage -Each node uses a connection object to hold and share Salesforce connected app settings (consumer key, consumer secret, username, etc.). This determines the org that each node operates against. +

Each node uses a connection object to hold and share Salesforce connected app settings (consumer key, consumer secret, username, etc.). This determines the org that each node operates against.

+

The credential fields can be left blank and passed in the message (msg.sf), this allows you to store them outside of the flow so that they will not be exposed when exporting it.

### SOQL diff --git a/connection-config.html b/connection-config.html index aee9ec8..65240d8 100644 --- a/connection-config.html +++ b/connection-config.html @@ -3,12 +3,12 @@ category: 'config', defaults: { name: {value:'', required: true}, - consumerKey: {required: true}, - consumerSecret: {required: true}, + consumerKey: {value:''}, + consumerSecret: {value:''}, callbackUrl: {required: true}, environment: {value: 'production', required: true}, - username: {required: true}, - password: {required: true}, + username: {value:''}, + password: {value:''}, }, label: function() { return this.name || this.username + ' connection'; @@ -50,11 +50,11 @@
- +
- +
@@ -69,10 +69,10 @@
- +
- +
diff --git a/dml.js b/dml.js index 8a76038..8ca8c2a 100644 --- a/dml.js +++ b/dml.js @@ -20,6 +20,22 @@ module.exports = function(RED) { config.object = msg.object; } + // get credentials from msg.sf if present and config values are blank + if (msg.hasOwnProperty("sf")) { + if (msg.sf.consumerKey && this.connection.consumerKey === '') { + this.connection.consumerKey = msg.sf.consumerKey; + } + if (msg.sf.consumerSecret && this.connection.consumerSecret === '') { + this.connection.consumerSecret = msg.sf.consumerSecret; + } + if (msg.sf.username && this.connection.username === '') { + this.connection.username = msg.sf.username; + } + if (msg.sf.password && this.connection.password === '') { + this.connection.password = msg.sf.password; + } + } + // create connection object var org = nforce.createConnection({ clientId: this.connection.consumerKey, diff --git a/package.json b/package.json index e5e8ba7..414fae8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-contrib-salesforce", - "version": "0.0.5", + "version": "0.0.6", "description": "A set of Node-RED nodes to interact with Salesforce and Force.com.", "author": { "name": "Jeff Douglas", diff --git a/soql.js b/soql.js index 839d9bc..98e4797 100644 --- a/soql.js +++ b/soql.js @@ -16,6 +16,22 @@ module.exports = function(RED) { config.query = msg.query; } + // get credentials from msg.sf if present and config values are blank + if (msg.hasOwnProperty("sf")) { + if (msg.sf.consumerKey && this.connection.consumerKey === '') { + this.connection.consumerKey = msg.sf.consumerKey; + } + if (msg.sf.consumerSecret && this.connection.consumerSecret === '') { + this.connection.consumerSecret = msg.sf.consumerSecret; + } + if (msg.sf.username && this.connection.username === '') { + this.connection.username = msg.sf.username; + } + if (msg.sf.password && this.connection.password === '') { + this.connection.password = msg.sf.password; + } + } + // create connection object var org = nforce.createConnection({ clientId: this.connection.consumerKey, diff --git a/sosl.js b/sosl.js index 309a6f3..8233ee1 100644 --- a/sosl.js +++ b/sosl.js @@ -16,6 +16,22 @@ module.exports = function(RED) { config.query = msg.query; } + // get credentials from msg.sf if present and config values are blank + if (msg.hasOwnProperty("sf")) { + if (msg.sf.consumerKey && this.connection.consumerKey === '') { + this.connection.consumerKey = msg.sf.consumerKey; + } + if (msg.sf.consumerSecret && this.connection.consumerSecret === '') { + this.connection.consumerSecret = msg.sf.consumerSecret; + } + if (msg.sf.username && this.connection.username === '') { + this.connection.username = msg.sf.username; + } + if (msg.sf.password && this.connection.password === '') { + this.connection.password = msg.sf.password; + } + } + // create connection object var org = nforce.createConnection({ clientId: this.connection.consumerKey, diff --git a/streaming.js b/streaming.js index e5a026b..85a5949 100644 --- a/streaming.js +++ b/streaming.js @@ -7,6 +7,22 @@ module.exports = function(RED) { this.connection = RED.nodes.getNode(config.connection); var node = this; + // get credentials from msg.sf if present and config values are blank + if (msg.hasOwnProperty("sf")) { + if (msg.sf.consumerKey && this.connection.consumerKey === '') { + this.connection.consumerKey = msg.sf.consumerKey; + } + if (msg.sf.consumerSecret && this.connection.consumerSecret === '') { + this.connection.consumerSecret = msg.sf.consumerSecret; + } + if (msg.sf.username && this.connection.username === '') { + this.connection.username = msg.sf.username; + } + if (msg.sf.password && this.connection.password === '') { + this.connection.password = msg.sf.password; + } + } + // create connection object var org = nforce.createConnection({ clientId: this.connection.consumerKey,