Skip to content

Commit b235597

Browse files
committed
fix bug when using external service
1 parent 5fe73b2 commit b235597

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

77-cloudant-cf.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
</div>
2323

2424
<div class="form-row">
25-
<label for="node-config-input-user"><i class="fa fa-user"></i> Username</label>
26-
<input type="text" id="node-config-input-user">
25+
<label for="node-config-input-username"><i class="fa fa-user"></i> Username</label>
26+
<input type="text" id="node-config-input-username">
2727
</div>
2828

2929
<div class="form-row">
@@ -52,8 +52,8 @@
5252
},
5353
oneditprepare: function() {
5454
$.getJSON("cloudant/"+this.id, function(data) {
55-
if (data.user) {
56-
$("#node-config-input-user").val(data.user);
55+
if (data.username) {
56+
$("#node-config-input-username").val(data.username);
5757
}
5858
if (data.hasPassword) {
5959
$("#node-config-input-pass").val("__PWRD__");
@@ -63,10 +63,10 @@
6363
});
6464
},
6565
oneditsave: function() {
66-
var newUser = $("#node-config-input-user").val();
66+
var newUser = $("#node-config-input-username").val();
6767
var newPass = $("#node-config-input-pass").val();
6868
var credentials = {};
69-
credentials.user = newUser;
69+
credentials.username = newUser;
7070
if (newPass != "__PWRD__") {
7171
credentials.password = newPass;
7272
}

77-cloudant-cf.js

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module.exports = function(RED) {
5050
if (credentials) {
5151
res.send(JSON.stringify(
5252
{
53-
user: credentials.user,
53+
username: credentials.username,
5454
hasPassword: (credentials.password && credentials.password !== "")
5555
}
5656
));
@@ -68,10 +68,10 @@ module.exports = function(RED) {
6868
var newCreds = req.body;
6969
var credentials = RED.nodes.getCredentials(req.params.id) || {};
7070

71-
if (newCreds.user == null || newCreds.user == "") {
72-
delete credentials.user;
71+
if (newCreds.username == null || newCreds.username == "") {
72+
delete credentials.username;
7373
} else {
74-
credentials.user = newCreds.user;
74+
credentials.username = newCreds.username;
7575
}
7676

7777
if (newCreds.password == "") {
@@ -95,7 +95,7 @@ module.exports = function(RED) {
9595

9696
var credentials = RED.nodes.getCredentials(n.id);
9797
if (credentials) {
98-
this.username = credentials.user;
98+
this.username = credentials.username;
9999
this.password = credentials.password;
100100
}
101101

@@ -117,11 +117,11 @@ module.exports = function(RED) {
117117
this.operation = n.operation;
118118
this.payonly = n.payonly || false;
119119
this.database = n.database;
120-
this.cloudantConfig = RED.nodes.getNode(n.cloudant);
120+
this.cloudantConfig = _getCloudantConfig(n);
121121

122122
var node = this;
123123
var credentials = {
124-
account: node.cloudantConfig.credentials.user,
124+
account: node.cloudantConfig.credentials.username,
125125
password: node.cloudantConfig.credentials.password
126126
};
127127

@@ -213,7 +213,7 @@ module.exports = function(RED) {
213213
function CloudantInNode(n) {
214214
RED.nodes.createNode(this,n);
215215

216-
this.cloudantConfig = RED.nodes.getNode(n.cloudant);
216+
this.cloudantConfig = _getCloudantConfig(n);
217217
this.database = n.database;
218218
this.search = n.search;
219219
this.design = n.design;
@@ -222,7 +222,7 @@ module.exports = function(RED) {
222222

223223
var node = this;
224224
var credentials = {
225-
account: node.cloudantConfig.credentials.user,
225+
account: node.cloudantConfig.credentials.username,
226226
password: node.cloudantConfig.credentials.password
227227
};
228228

@@ -320,18 +320,11 @@ module.exports = function(RED) {
320320
}
321321
RED.nodes.registerType("cloudant in", CloudantInNode);
322322

323-
function _getUrl(node, n) {
324-
if (n.service == "_ext_") {
325-
var cloudantConfig = RED.nodes.getNode(node.cloudantConfig);
326-
if (cloudantConfig) {
327-
return cloudantConfig.url;
328-
}
329-
}
330-
else if (n.service != "") {
331-
var cloudantConfig = appEnv.getService(n.service);
332-
if (cloudantConfig) {
333-
return cloudantConfig.credentials.url;
334-
}
323+
function _getCloudantConfig(n) {
324+
if (n.service === "_ext_") {
325+
return RED.nodes.getNode(n.cloudant);
326+
} else if (n.service !== "") {
327+
return appEnv.getService(n.service);
335328
}
336329
}
337330
};

0 commit comments

Comments
 (0)