Skip to content

Commit

Permalink
Merge pull request #8 from dowjones/release/1.1.1
Browse files Browse the repository at this point in the history
Release/1.1.1
  • Loading branch information
dj-dna-andersend authored Nov 19, 2018
2 parents 13aeeff + 5851acc commit aa5d6cc
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
11 changes: 9 additions & 2 deletions config/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Config {
CLIENT_ID_ENV: 'CLIENT_ID',
PASSWORD_ENV: 'PASSWORD',
USER_KEY_ENV: 'USER_KEY',
SERVICE_ACCOUNT_ID_ENV: 'SERVICE_ACCOUNT_ID',
SUBSCRIPTION_ID_ENV: 'SUBSCRIPTION_ID',
EXTRACTION_API_HOST_ENV: 'EXTRACTION_API_HOST',
EXTRACTION_API_HOST_DEFAULT: 'https://api.dowjones.com',
Expand Down Expand Up @@ -56,6 +57,11 @@ class Config {
}
}

// NOTE: "service_account_id" is a legacy, alternate name for "user_key" from the customer's perspective
if (!accountCreds.user_key && accountCreds.service_account_id) {
accountCreds.user_key = accountCreds.service_account_id;
}

return this._areCredsSet(accountCreds) ? accountCreds : new Error(
'Error: No account credentials specified\n' +
'Must specify user_id, client_id, and password as args to Listener constructor, env vars, or via customerConfig.json file\n' +
Expand All @@ -68,12 +74,13 @@ class Config {
user_id: process.env[this.Constants.USER_ID_ENV],
client_id: process.env[this.Constants.CLIENT_ID_ENV],
password: process.env[this.Constants.PASSWORD_ENV],
user_key: process.env[this.Constants.USER_KEY_ENV]
user_key: process.env[this.Constants.USER_KEY_ENV],
service_account_id: process.env[this.Constants.SERVICE_ACCOUNT_ID_ENV]
};
}

_areCredsSet(accountCreds) {
return accountCreds && (accountCreds.user_key || (accountCreds.user_id && accountCreds.client_id && accountCreds.password));
return accountCreds && (accountCreds.user_key || accountCreds.service_account_id || (accountCreds.user_id && accountCreds.client_id && accountCreds.password));
}
}

Expand Down
1 change: 1 addition & 0 deletions config/ConfigFileUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ConfigFileUtil {

return {
user_key: _.trim(this.config.user_key),
service_account_id: _.trim(this.config.service_account_id),
user_id: _.trim(this.config.user_id),
client_id: _.trim(this.config.client_id),
password: _.trim(this.config.password)
Expand Down
7 changes: 7 additions & 0 deletions tests/config/testCustomerConfigServiceAccountId.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"service_account_id": "foo",
"user_id": "[email protected]",
"client_id": "clientID123",
"password": "Password123",
"subscription_id": "bar"
}
14 changes: 14 additions & 0 deletions tests/configFileUtilTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const path = require('path');
describe('configFileUtil', () => {
let sandbox;
const pathConfig = path.join(__dirname, './config/testCustomerConfig.json');
const serviceAccountIdPathConfig = path.join(__dirname, './config/testCustomerConfigServiceAccountId.json');

beforeEach(() => {
sandbox = sinon.sandbox.create();
Expand All @@ -28,6 +29,19 @@ describe('configFileUtil', () => {
expect(userKey).toBe('foo');
});

it('should get the correct customer user key when set with service_account_id param.', () => {
// Arrange
const configFileUtil = new ConfigFileUtil();
configFileUtil.setConfigFilePath(serviceAccountIdPathConfig);

// Act
const creds = configFileUtil.getAccountCredentials();
const userKey = creds.service_account_id;

// Assert
expect(userKey).toBe('foo');
});

it('should get the correct customer service account credentials.', () => {
// Arrange
const configFileUtil = new ConfigFileUtil();
Expand Down
27 changes: 27 additions & 0 deletions tests/configTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ describe('config', () => {
expect(actualUserKey).toBe(expectedUserKey);
});

it('should prioritize service_account_id from env over service account creds in config file', () => {
// Arrange
const expectedUserKey = '123A';
process.env[config.Constants.SERVICE_ACCOUNT_ID_ENV] = expectedUserKey;

// Act
const creds = config.getAccountCredentials();
const actualUserKey = creds.user_key;

// Assert
expect(actualUserKey).toBe(expectedUserKey);
});

it('should prioritize credentials set thru env vars over config file', () => {
// Arrange
const expectedUserId = 'userId';
Expand Down Expand Up @@ -109,6 +122,20 @@ describe('config', () => {
expect(accountCreds.user_id).toBe(undefined);
});

it('should prioritize service_account_id param over service account credentials in config file', () => {
// Arrange
const userKeyExpected = '123';
const configSpecial = new Config({ service_account_id: userKeyExpected });

// Act
const accountCreds = configSpecial.getAccountCredentials();
const userKeyActual = accountCreds.user_key;

// Assert
expect(userKeyExpected).toBe(userKeyActual);
expect(accountCreds.user_id).toBe(undefined);
});

it('should get the correct subscription ID from config file if no overrides present.', () => {
// Arrange
const expectedSub = 'bar';
Expand Down

0 comments on commit aa5d6cc

Please sign in to comment.