Skip to content

Commit

Permalink
Merge pull request randsleadershipslack#169 from TheConnMan/array-env…
Browse files Browse the repository at this point in the history
…-vars

Filter out empty list items from array environment variables
  • Loading branch information
kmarekspartz authored Dec 16, 2017
2 parents 25cacb4 + 833f590 commit d68af64
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ These channels need to be manually created by you in your Slack.

### Environment variables

All configs in `configuration.yaml` are overrideable through environment variables with the same name prefixed by `DESTALINATOR_` (e.g. `activated` -> `DESTALINATOR_ACTIVATED`). Set array environment variables (e.g. `DESTALINATOR_IGNORE_CHANNELS`) by comma delimiting items
All configs in `configuration.yaml` are overrideable through environment variables with the same name prefixed by `DESTALINATOR_` (e.g. `activated` -> `DESTALINATOR_ACTIVATED`). Set array environment variables (e.g. `DESTALINATOR_IGNORE_CHANNELS`) by comma delimiting items. If you only have one value for an array type environment variable add a training comma to denote the variable as a list.

#### `DESTALINATOR_SB_TOKEN` (Required)

Expand Down
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __getattr__(self, attrname):
else:
envvar = os.getenv('DESTALINATOR_' + upper_attrname)
if envvar is not None:
return envvar.split(',') if ',' in envvar else envvar
return [x for x in envvar.split(',') if x] if ',' in envvar else envvar

return self.config.get(attrname, '')

Expand Down
14 changes: 14 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import unittest

from config import get_config


class ConfigTest(unittest.TestCase):
def setUp(self):
os.environ['DESTALINATOR_STRING_VARIABLE'] = 'test'
os.environ['DESTALINATOR_LIST_VARIABLE'] = 'test,'

def test_environment_variable_configs(self):
self.assertEqual(get_config().string_variable, 'test')
self.assertListEqual(get_config().list_variable, ['test'])

0 comments on commit d68af64

Please sign in to comment.