Skip to content

Commit

Permalink
take the last credentials for a service instance
Browse files Browse the repository at this point in the history
  • Loading branch information
germanattanasio committed Oct 1, 2015
1 parent 0138529 commit 7231d55
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* if VCAP_SERVICES exists then it returns the credentials
* for the first service that stars with 'name' or {} otherwise
* for the last service that stars with 'name' or {} otherwise
* @param String name, service name
* @return {Object} the service credentials or {} if
* name is not found in VCAP_SERVICES
Expand All @@ -12,10 +12,10 @@ module.exports.getCredentials = function(name) {
var services = JSON.parse(process.env.VCAP_SERVICES);
for (var service_name in services) {
if (service_name.indexOf(name) === 0) {
var service = services[service_name][0];
var service = services[service_name][services[service_name].length - 1];
return service.credentials || {};
}
}
}
return {};
};
};
2 changes: 2 additions & 0 deletions test/test.parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ describe('vcap_services', function() {
// set VCAP_SERVICES to a default value
process.env.VCAP_SERVICES = JSON.stringify({
personality_insights: [{
plan: 'beta'
},{
credentials: credentials,
label: 'personality_insights',
name: 'personality-insights-service',
Expand Down

0 comments on commit 7231d55

Please sign in to comment.