Skip to content

Commit 778ae06

Browse files
authored
Merge pull request #410 from chughts/vrauth
Visual Recognition Authentication
2 parents cf48783 + 42f56e0 commit 778ae06

File tree

4 files changed

+70
-14
lines changed

4 files changed

+70
-14
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ Node-RED Watson Nodes for IBM Cloud
77

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

10+
### New in version 0.6.14
11+
- Visual Recognition instances created post May 22 2018, have a new authentication mechanism
12+
1013
### New in version 0.6.13
11-
- Added opt-out option for collection parsing of strings in Natural Language Classifier Node.
14+
- Added opt-out option for collection parsing of strings in Natural Language Classifier Node.
1215

1316
### New in version 0.6.12
1417
- Fix to collection check in Natural Language Classification Node allowing for . in domain

package.json

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-watson",
3-
"version": "0.6.13",
3+
"version": "0.6.14",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"async": "^1.5.2",
@@ -9,13 +9,13 @@
99
"request": "~2.86.0",
1010
"temp": "^0.8.3",
1111
"qs": "6.x",
12-
"image-type": "^2.0.2",
13-
"watson-developer-cloud": "^3.3.0",
12+
"image-type": "^2.0.2",
13+
"watson-developer-cloud": "^3.4.2",
1414
"kuromoji": "^0.1.1",
1515
"word-count": "^0.2.2",
1616
"is-docx": "^0.0.3",
17-
"stream-to-array" : "^2.3.0",
18-
"ws" : "^4.1.0"
17+
"stream-to-array": "^2.3.0",
18+
"ws": "^4.1.0"
1919
},
2020
"repository": {
2121
"type": "git",
@@ -27,18 +27,19 @@
2727
"bluemix",
2828
"watson"
2929
],
30-
"contributors": [ {
30+
"contributors": [
31+
{
3132
"name": "Soheel Chughtai",
3233
"email": "soheel_chughtai@uk.ibm.com"
3334
}
3435
],
3536
"node-red": {
3637
"nodes": {
37-
"watson-conversation-v1":"services/conversation/v1.js",
38-
"watson-conversation-workspace-manager-v1":"services/conversation/v1-workspace-manager.js",
39-
"watson-discovery-v1":"services/discovery/v1.js",
40-
"watson-discovery-v1-document-loader":"services/discovery/v1-document-loader.js",
41-
"watson-discovery-v1-query-builder":"services/discovery/v1-query-builder.js",
38+
"watson-conversation-v1": "services/conversation/v1.js",
39+
"watson-conversation-workspace-manager-v1": "services/conversation/v1-workspace-manager.js",
40+
"watson-discovery-v1": "services/discovery/v1.js",
41+
"watson-discovery-v1-document-loader": "services/discovery/v1-document-loader.js",
42+
"watson-discovery-v1-query-builder": "services/discovery/v1-query-builder.js",
4243
"watson-language-translator-v2": "services/language_translator/v2.js",
4344
"watson-language-translator-identify-v2": "services/language_translator_identify/v2.js",
4445
"watson-language-translator-util-v2": "services/language_translator_util/v2.js",

services/visual_recognition/v3.html

+18
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
<label for="node-input-apikey"><i class="fa fa-key"></i> API Key</label>
2525
<input type="password" id="node-input-apikey" placeholder="API Key">
2626
</div>
27+
<div class="form-row">
28+
<label for="node-input-vr-service-endpoint"><i class="fa fa-tag"></i> Service Endpoint</label>
29+
<select type="text" id="node-input-vr-service-endpoint" style="display: inline-block; width: 70%;" >
30+
<option value="https://gateway-a.watsonplatform.net/visual-recognition/api">https://gateway-a.watsonplatform.net/visual-recognition/api</option>
31+
<option value="https://gateway.watsonplatform.net/visual-recognition/api">https://gateway.watsonplatform.net/visual-recognition/api</option>
32+
</select>
33+
</div>
34+
2735
<div class="form-row">
2836
<label for="node-input-image-feature"><i class="fa fa-book"></i> Detect: </label>
2937
<select type="text" id="node-input-image-feature" style="display: inline-block; width: 70%;">
@@ -61,6 +69,14 @@
6169
<label for="node-input-apikey"><i class="fa fa-key"></i> API Key</label>
6270
<input type="password" id="node-input-apikey" placeholder="API Key">
6371
</div>
72+
<div class="form-row">
73+
<label for="node-input-vr-service-endpoint"><i class="fa fa-tag"></i> Service Endpoint</label>
74+
<select type="text" id="node-input-vr-service-endpoint" style="display: inline-block; width: 70%;" >
75+
<option value="https://gateway-a.watsonplatform.net/visual-recognition/api">https://gateway-a.watsonplatform.net/visual-recognition/api</option>
76+
<option value="https://gateway.watsonplatform.net/visual-recognition/api">https://gateway.watsonplatform.net/visual-recognition/api</option>
77+
</select>
78+
</div>
79+
6480
<div class="form-row">
6581
<label for="node-input-image-feature"><i class="fa fa-book"></i> Detect: </label>
6682
<select type="text" id="node-input-image-feature" style="display: inline-block; width: 70%;">
@@ -148,6 +164,7 @@
148164
defaults: {
149165
name: {value: ""},
150166
apikey: {value: ""},
167+
'vr-service-endpoint' :{value: 'https://gateway-a.watsonplatform.net/visual-recognition/api'},
151168
"image-feature": {value: ""},
152169
"lang": {value: ""},
153170
},
@@ -216,6 +233,7 @@
216233
defaults: {
217234
name: {value: ""},
218235
apikey: {value: ""},
236+
'vr-service-endpoint' :{value: 'https://gateway-a.watsonplatform.net/visual-recognition/api'},
219237
"image-feature": {value: ""}
220238
},
221239
credentials: {

services/visual_recognition/v3.js

+36-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ module.exports = function(RED) {
4040
async = require('async'),
4141
toArray = require('stream-to-array'),
4242
sAPIKey = null,
43-
service = null;
43+
iamAPIKey = false,
44+
service = null,
45+
endpoint = '',
46+
sEndpoint = '';
4447

4548
// temp is being used for file streaming to allow the file to arrive so it can be processed.
4649
temp.track();
@@ -49,6 +52,7 @@ module.exports = function(RED) {
4952

5053
if (service) {
5154
sAPIKey = service.api_key;
55+
sEndpoint = service.url;
5256
}
5357

5458
RED.httpAdmin.get('/watson-visual-recognition/vcap', function(req, res) {
@@ -154,13 +158,23 @@ module.exports = function(RED) {
154158
}
155159

156160
var serviceSettings = {
157-
api_key: node.apikey,
158161
version_date: '2018-03-19',
159162
headers: {
160163
'User-Agent': pkg.name + '-' + pkg.version
161164
}
162165
};
163166

167+
if (endpoint) {
168+
serviceSettings.url = endpoint;
169+
}
170+
171+
// VR instances created post 22 May 2018, are expecting an iam API Key
172+
if (iamAPIKey) {
173+
serviceSettings.iam_apikey = node.apikey;
174+
} else {
175+
serviceSettings.api_key = node.apikey;
176+
}
177+
164178
// The change to watson-developer-cloud 3.0.x has resulted in a
165179
// change in how the Accept-Language is specified. It now needs
166180
// to go in as a header.
@@ -469,6 +483,7 @@ module.exports = function(RED) {
469483
shape: 'dot',
470484
text: 'Calling ' + feature + ' ...'
471485
});
486+
472487
if (feature === 'classifyImage' || feature === 'detectFaces') {
473488
return executeService(feature, params, node, msg);
474489
//return Promise.resolve();
@@ -481,6 +496,22 @@ module.exports = function(RED) {
481496
}
482497
}
483498

499+
function determineEndpoint(config) {
500+
// Any VR instances created post 22 May 2018, have a different endpoint
501+
// and mechanism for authentication. This function detemines if this
502+
// new authentication mechanism is being utlised.
503+
iamAPIKey = false;
504+
505+
endpoint = sEndpoint;
506+
if (!endpoint && config['vr-service-endpoint']) {
507+
endpoint = config['vr-service-endpoint'];
508+
}
509+
if (endpoint && 'https://gateway.watsonplatform.net/visual-recognition/api' === endpoint) {
510+
iamAPIKey = true;
511+
}
512+
return Promise.resolve();
513+
}
514+
484515
// This is the Watson Visual Recognition V3 Node
485516
function WatsonVisualRecognitionV3Node(config) {
486517
var node = this,
@@ -506,6 +537,9 @@ module.exports = function(RED) {
506537
.then(function() {
507538
return verifyInputs(feature, msg);
508539
})
540+
.then(function() {
541+
return determineEndpoint(config);
542+
})
509543
.then(function() {
510544
return verifyServiceCredentials(node, msg);
511545
})

0 commit comments

Comments
 (0)