Skip to content

Commit a9beb2f

Browse files
committed
Fix Visual Recognition v3 to accept credentials from VCAP_SERVICES environment property in bluemix.
This is a prerequesite for germanattanasio/visual-recognition-nodejs#88
1 parent f3d1b90 commit a9beb2f

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lib/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ function createServiceAPI(serviceName) {
6464

6565
// Get credentials from Bluemix
6666
if (options.use_vcap_services !== false) {
67-
var credentials = vcapServices.getCredentials(serviceName);
67+
var vcap_services_name = vrv3 ? 'watson_vision_combined' : serviceName;
68+
var credentials = vcapServices.getCredentials(vcap_services_name);
6869
if (credentials.username && credentials.password) {
6970
credentials.api_key = encodeBase64(credentials);
7071
}

test/test.visual_recognition.v3.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,41 @@ describe('visual_recognition', function() {
8686
assert((err instanceof Error) && /parameter/.test(err), 'Expected error to mention "parameter" but got "' + (err && err.message || err) + '"');
8787
};
8888

89+
describe('credentials', function() {
90+
var env;
91+
before(function() {
92+
env = process.env;
93+
process.env = {
94+
VCAP_SERVICES: JSON.stringify({
95+
"watson_vision_combined": [
96+
{
97+
"name": "Visual Recognition-mj",
98+
"label": "watson_vision_combined",
99+
"plan": "free",
100+
"credentials": {
101+
"url": "https://gateway-a.watsonplatform.net/visual-recognition/api",
102+
"note": "It may take up to 5 minutes for this key to become active",
103+
"api_key": "foo"
104+
}
105+
}
106+
]
107+
})
108+
};
109+
});
110+
after(function() {
111+
process.env = env;
112+
});
113+
114+
it('should read credentials from cf/bluemix environment properties', function() {
115+
var instance = watson.visual_recognition({
116+
version: 'v3',
117+
version_date: '2016-05-20'
118+
});
119+
assert(instance._options.qs.api_key, 'foo');
120+
});
121+
});
122+
123+
89124
describe('version_date', function() {
90125
it('should check no version_date provided', function(done) {
91126
try {

0 commit comments

Comments
 (0)