Skip to content

Commit 4a70ca8

Browse files
committed
Implement iam for Personality Insights
1 parent 51f16d5 commit 4a70ca8

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Node-RED Watson Nodes for IBM Cloud
88
<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>
99

1010
### New in version 0.7.0
11-
- Assistant, Discovery, Natural Language Understanding, Speech to Text, Text to Speech, Tone Analyzer nodes updated
11+
- Assistant, Discovery, Natural Language Understanding, Personality Insights,
12+
Speech to Text, Text to Speech, Tone Analyzer nodes updated
1213
to allow for use of iam key for authentication.
1314
- Migrated STT node off deprecated methods.
1415
- Fix to Tone Analyzer Node to preserve credentials on config reopen.

services/personality_insights/v3.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
<label for="node-input-password"><i class="fa fa-key"></i> Password</label>
3333
<input type="password" id="node-input-password" placeholder="Password">
3434
</div>
35+
<div class="form-row credentials" style="display: none;">
36+
<label for="node-input-apikey"><i class="fa fa-key"></i> API Key</label>
37+
<input type="password" id="node-input-apikey" placeholder="API Key"></input>
38+
</div>
3539

3640
<div class="form-row credentials">
3741
<label>&nbsp;</label>
@@ -125,7 +129,8 @@
125129
},
126130
credentials: {
127131
username: {type:"text"},
128-
password: {type:"password"}
132+
password: {type:"password"},
133+
apikey: {type: 'password'}
129134
},
130135
color: "rgb(0, 150, 200)",
131136
inputs: 1,

services/personality_insights/v3.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@ module.exports = function (RED) {
2525
password = null,
2626
sUsername = null,
2727
sPassword = null,
28+
apikey = null,
29+
sApikey = null,
2830
endpoint = '',
2931
sEndpoint = 'https://gateway.watsonplatform.net/personality-insights/api',
3032

3133
VALID_INPUT_LANGUAGES = ['ar','en','es','ja'],
3234
VALID_RESPONSE_LANGUAGES = ['ar','de','en','es','fr','it','ja','ko','pt-br','zh-cn','zh-tw'];
3335

34-
if (service) {
35-
sUsername = service.username;
36-
sPassword = service.password;
37-
sEndpoint = service.url;
38-
}
36+
if (service) {
37+
sUsername = service.username ? service.username : '';
38+
sPassword = service.password ? service.password : '';
39+
sApikey = service.apikey ? service.apikey : '';
40+
sEndpoint = service.url;
41+
}
3942

4043
// This HTTP GET REST request is used by the browser side of the node to
4144
// determine if credentials are found.
@@ -72,8 +75,9 @@ module.exports = function (RED) {
7275
function credentialsCheck(node) {
7376
username = sUsername || node.credentials.username;
7477
password = sPassword || node.credentials.password;
78+
apikey = sApikey || node.credentials.apikey;
7579

76-
if (!username || !password) {
80+
if (!apikey && (!username || !password)) {
7781
return Promise.reject('Missing Personality Insights service credentials');
7882
}
7983
return Promise.resolve();
@@ -123,14 +127,19 @@ module.exports = function (RED) {
123127
var p = new Promise(function resolver(resolve, reject) {
124128
var personality_insights = null,
125129
serviceSettings = {
126-
username: username,
127-
password: password,
128130
version_date: '2016-10-20',
129131
headers: {
130132
'User-Agent': pkg.name + '-' + pkg.version
131133
}
132134
};
133135

136+
if (apikey) {
137+
serviceSettings.iam_apikey = apikey;
138+
} else {
139+
serviceSettings.username = username;
140+
serviceSettings.password = password;
141+
}
142+
134143
if (endpoint) {
135144
serviceSettings.url = endpoint;
136145
}
@@ -191,7 +200,8 @@ module.exports = function (RED) {
191200
RED.nodes.registerType('watson-personality-insights-v3',Node,{
192201
credentials: {
193202
username: {type:'text'},
194-
password: {type:'password'}
203+
password: {type:'password'},
204+
apikey: {type:'password'}
195205
}
196206
});
197207
};

0 commit comments

Comments
 (0)