Skip to content

Commit

Permalink
Merge pull request #20 from mamoonraja/fix-kube-env
Browse files Browse the repository at this point in the history
fix(kubeEnv): processing of env variables for kube
  • Loading branch information
germanattanasio committed Aug 20, 2018
2 parents 7e8fd41 + 569e547 commit 79ea0c1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 24 deletions.
17 changes: 2 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,6 @@ const getCredentialsFromLocalConfig = function(serviceLabel, credentials) {
return creds;
}

/**
* Returns all the credentials that match the service label from env variables
*
* @param {string} serviceLabel The service label
* @param {object} credentials The credentials for starterkit from Kube Env
*/
const getCredentialsFromKubeEnv = function(serviceLabel) {
const credentials = process.env[`service_watson_${serviceLabel}`];
const creds = credentials ? getCredentialsFromLocalConfig(serviceLabel, JSON.parse(credentials)) : {};
return creds;
}

/**
* Returns all the credentials that match the service label from env variables
*
Expand All @@ -100,15 +88,14 @@ const getCredentialsForStarter = function(serviceLabel, credsFromFile) {
else if (process.env.VCAP_SERVICES) {
creds = getCredentials(serviceLabel);
}
else {
creds = getCredentialsFromKubeEnv(serviceLabel);
else if (process.env[`service_watson_${serviceLabel}`]){
creds = JSON.parse(process.env[`service_watson_${serviceLabel}`]);
}
return creds;
}

module.exports = {
getCredentials,
getCredentialsFromKubeEnv,
getCredentialsFromLocalConfig,
getCredentialsForStarter,
};
10 changes: 1 addition & 9 deletions test/test.parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,10 @@ describe('credentials file and Kube', function() {
assert.deepEqual(credentials, vcapServices.getCredentialsFromLocalConfig('conversation', cloudCredentials));
});

it('should return no credentials for Kube', function() {
assert.deepEqual({}, vcapServices.getCredentialsFromKubeEnv('conversation'));
});

it('should return the credentials for Kube', function() {
process.env.service_watson_conversation = JSON.stringify(cloudCredentials);
assert.deepEqual(credentials, vcapServices.getCredentialsFromKubeEnv('conversation'));
});

it('should get the credentials for Starter from Kube', function() {
process.env.service_watson_conversation = JSON.stringify(cloudCredentials);
assert.deepEqual(credentials, vcapServices.getCredentialsForStarter('conversation'));
assert.deepEqual(cloudCredentials, vcapServices.getCredentialsForStarter('conversation'));
});

it('should get the credentials for Starter from file', function() {
Expand Down

0 comments on commit 79ea0c1

Please sign in to comment.