Skip to content

Commit

Permalink
Implement iam for Personality Insights
Browse files Browse the repository at this point in the history
  • Loading branch information
chughts committed Jun 7, 2018
1 parent 51f16d5 commit 4a70ca8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Node-RED Watson Nodes for IBM Cloud
<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>

### New in version 0.7.0
- Assistant, Discovery, Natural Language Understanding, Speech to Text, Text to Speech, Tone Analyzer nodes updated
- Assistant, Discovery, Natural Language Understanding, Personality Insights,
Speech to Text, Text to Speech, Tone Analyzer nodes updated
to allow for use of iam key for authentication.
- Migrated STT node off deprecated methods.
- Fix to Tone Analyzer Node to preserve credentials on config reopen.
Expand Down
7 changes: 6 additions & 1 deletion services/personality_insights/v3.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<label for="node-input-password"><i class="fa fa-key"></i> Password</label>
<input type="password" id="node-input-password" placeholder="Password">
</div>
<div class="form-row credentials" style="display: none;">
<label for="node-input-apikey"><i class="fa fa-key"></i> API Key</label>
<input type="password" id="node-input-apikey" placeholder="API Key"></input>
</div>

<div class="form-row credentials">
<label>&nbsp;</label>
Expand Down Expand Up @@ -125,7 +129,8 @@
},
credentials: {
username: {type:"text"},
password: {type:"password"}
password: {type:"password"},
apikey: {type: 'password'}
},
color: "rgb(0, 150, 200)",
inputs: 1,
Expand Down
28 changes: 19 additions & 9 deletions services/personality_insights/v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ module.exports = function (RED) {
password = null,
sUsername = null,
sPassword = null,
apikey = null,
sApikey = null,
endpoint = '',
sEndpoint = 'https://gateway.watsonplatform.net/personality-insights/api',

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

if (service) {
sUsername = service.username;
sPassword = service.password;
sEndpoint = service.url;
}
if (service) {
sUsername = service.username ? service.username : '';
sPassword = service.password ? service.password : '';
sApikey = service.apikey ? service.apikey : '';
sEndpoint = service.url;
}

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

if (!username || !password) {
if (!apikey && (!username || !password)) {
return Promise.reject('Missing Personality Insights service credentials');
}
return Promise.resolve();
Expand Down Expand Up @@ -123,14 +127,19 @@ module.exports = function (RED) {
var p = new Promise(function resolver(resolve, reject) {
var personality_insights = null,
serviceSettings = {
username: username,
password: password,
version_date: '2016-10-20',
headers: {
'User-Agent': pkg.name + '-' + pkg.version
}
};

if (apikey) {
serviceSettings.iam_apikey = apikey;
} else {
serviceSettings.username = username;
serviceSettings.password = password;
}

if (endpoint) {
serviceSettings.url = endpoint;
}
Expand Down Expand Up @@ -191,7 +200,8 @@ module.exports = function (RED) {
RED.nodes.registerType('watson-personality-insights-v3',Node,{
credentials: {
username: {type:'text'},
password: {type:'password'}
password: {type:'password'},
apikey: {type:'password'}
}
});
};

0 comments on commit 4a70ca8

Please sign in to comment.