Skip to content

Commit

Permalink
feat(index): adds new function to append cloud functions service bind…
Browse files Browse the repository at this point in the history
… credentials
  • Loading branch information
Anwesha Naskar authored and Anwesha Naskar committed Oct 10, 2018
1 parent 79ea0c1 commit 8d893a2
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,35 @@ const getCredentialsFromLocalConfig = function(serviceLabel, credentials) {
return creds;
}

/**
* Helper function used to add credentials bound to cloud functions using wsk service bind
*
* @param {Object} theParams - parameters sent to service
* @param {string} service - name of service in bluemix used to retrieve credentials, used for IAM instances
* @param {string} serviceAltName - alternate name of service used for cloud foundry instances
* @return {Object} - returns parameters modified to include credentials from service bind
*/
const addCredentialsFromServiceBind = function(theParams, service, serviceAltName) {
if (Object.keys(theParams).length === 0) {
return theParams;
}
let bxCreds = {};
if (theParams.__bx_creds && theParams.__bx_creds[service]) {
// If user has IAM instance of service
bxCreds = theParams.__bx_creds[service];
} else if (theParams.__bx_creds && theParams.__bx_creds[serviceAltName]) {
// If user has no IAM instance of service, check for CF instances
bxCreds = theParams.__bx_creds[serviceAltName];
}
const _params = Object.assign({}, bxCreds, theParams);
if (_params.apikey) {
_params.iam_apikey = _params.apikey;
delete _params.apikey;
}
delete _params.__bx_creds;
return _params;
}

/**
* Returns all the credentials that match the service label from env variables
*
Expand All @@ -98,4 +127,5 @@ module.exports = {
getCredentials,
getCredentialsFromLocalConfig,
getCredentialsForStarter,
addCredentialsFromServiceBind,
};

0 comments on commit 8d893a2

Please sign in to comment.