Skip to content

Commit

Permalink
more fixes for the azure CUSTOMCONNSTR_ vars
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese committed Aug 3, 2015
1 parent 1330502 commit ec68db7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
14 changes: 10 additions & 4 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,21 @@ function hasExtendedSetting(prefix, envs) {

function findExtendedSettings (enables, envs) {
var extended = {};

function normalizeEnv (key) {
return key.toUpperCase().replace('CUSTOMCONNSTR_', '');
}

enables.split(' ').forEach(function eachEnable(enable) {
if (_.trim(enable)) {
_.forIn(envs, function eachEnvPair (value, key) {
if (_.startsWith(key, enable.toUpperCase() + '_') || _.startsWith(key, enable.toLowerCase() + '_')) {
var split = key.indexOf('_');
if (split > -1 && split <= key.length) {
var env = normalizeEnv(key);
if (_.startsWith(env, enable.toUpperCase() + '_')) {
var split = env.indexOf('_');
if (split > -1 && split <= env.length) {
var exts = extended[enable] || {};
extended[enable] = exts;
var ext = _.camelCase(key.substring(split + 1).toLowerCase());
var ext = _.camelCase(env.substring(split + 1).toLowerCase());
if (!isNaN(value)) { value = Number(value); }
exts[ext] = value;
}
Expand Down
13 changes: 10 additions & 3 deletions tests/env.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,30 @@ describe('env', function ( ) {

it('check if there are extended settings', function () {
var env = require('../env')();
env.hasExtendedSetting('PUSHOVER', {'PUSHOVER_API_TOKEN': '12345'}).should.equal(true);
env.hasExtendedSetting('PUSHOVER', {'PUSHOVER_API_TOKEN': 'abc12345'}).should.equal(true);
});

it('check if there are extended settings for azure', function () {
var env = require('../env')();
env.hasExtendedSetting('PUSHOVER', {'CUSTOMCONNSTR_PUSHOVER_API_TOKEN': 'abc12345'}).should.equal(true);
});

it('add pushover to enable if one of the env vars is set', function () {
process.env.PUSHOVER_API_TOKEN = '12345';
process.env.PUSHOVER_API_TOKEN = 'abc12345';

var env = require('../env')();
env.enable.should.containEql('pushover');
env.extendedSettings.pushover.apiToken.should.equal('abc12345');

delete process.env.PUSHOVER_API_TOKEN;
});

it('add pushover to enable if one of the weird azure env vars is set', function () {
process.env.CUSTOMCONNSTR_PUSHOVER_API_TOKEN = '12345';
process.env.CUSTOMCONNSTR_PUSHOVER_API_TOKEN = 'abc12345';

var env = require('../env')();
env.enable.should.containEql('pushover');
env.extendedSettings.pushover.apiToken.should.equal('abc12345');

delete process.env.PUSHOVER_API_TOKEN;
});
Expand Down

0 comments on commit ec68db7

Please sign in to comment.