Skip to content

Commit

Permalink
Merge pull request #14 from voltgrid/feature/strip-crlf-envs
Browse files Browse the repository at this point in the history
Strip CR/LF from environment variables
  • Loading branch information
macropin authored Aug 24, 2018
2 parents 9db3713 + 5035e30 commit 8478c25
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

### Environment

- `CONFIG` - alternative template context (json format).
- `VOLTGRID_PIE_DEBUG` set to `true` to enable environment variable debugging.
- `VG_CONF_PATH` - set path to `voltgrid.conf` (Default: `/usr/local/etc/voltgrid.conf`)
- `GIT_URL`
- `GIT_DST`

### voltgrid.conf

Expand Down
File renamed without changes.
12 changes: 10 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from voltgrid import ConfigManager

VG_CFG = 'voltgrid.conf'
VG_CFG = os.path.join(os.path.abspath(os.path.split(__file__)[0]), 'voltgrid.conf')


def test_config_manager():
Expand Down Expand Up @@ -37,4 +37,12 @@ def test_git_config_no_vgconf():
c = ConfigManager('does-not-exist')
c.load_git_conf()
assert(c.git_url == git_url)
assert(c.git_dst == git_dst)
assert(c.git_dst == git_dst)


def test_strip_crlf():
os.environ['VG_CONF_PATH'] = VG_CFG
os.environ['MYVARIABLE'] = '\r\nfoo \nbar\r' # Context
c = ConfigManager(VG_CFG)
c.load_config()
assert(c.config['MYVARIABLE'] == 'foo bar')
4 changes: 2 additions & 2 deletions tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def test_template_render():

def test_template_render_unicode():
os.environ['CONFIG'] = '{"USERNAME": "Héctor"}' # Context
template = '%s' % os.path.join(os.path.abspath(os.path.split(__file__)[0]), 'template.environment.test')
template = '%s' % os.path.join(os.path.abspath(os.path.split(__file__)[0]), 'template_test_unicode')
c = ConfigManager(VG_CFG)
c.load_config()
t = TemplateManager()
result = t.render(template, c.config)
assert('USERNAME=Héctor' in result)
assert('USERNAME=Héctor' in result)
10 changes: 7 additions & 3 deletions voltgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from distutils.dir_util import copy_tree


__version__ = '1.0.7'
__version__ = '1.0.8'

# Config
VG_CONF_PATH = '/usr/local/etc/voltgrid.conf'
VG_CONF_PATH = os.environ.get('VG_CONF_PATH', '/usr/local/etc/voltgrid.conf')

# Default ID for spawning and mounting, override in voltgrid.conf
DEFAULT_UID = 48
Expand Down Expand Up @@ -45,7 +45,11 @@ def load_config(self):
else:
self.config = {}
for key in self.environment.keys():
self.config[key] = os.environ[key]
# remove crlf from environment variables
value = str(os.environ[key])
value = ''.join(value.splitlines())
value = value.strip('\r\n')
self.config[key] = value

@staticmethod
def load_local_config(cfg_file):
Expand Down

0 comments on commit 8478c25

Please sign in to comment.