diff options
Diffstat (limited to 'src/leap')
-rw-r--r-- | src/leap/eip/config.py | 31 | ||||
-rw-r--r-- | src/leap/eip/tests/tests_config.py | 19 |
2 files changed, 47 insertions, 3 deletions
diff --git a/src/leap/eip/config.py b/src/leap/eip/config.py index a1dc2764..c77bb142 100644 --- a/src/leap/eip/config.py +++ b/src/leap/eip/config.py @@ -2,6 +2,7 @@ import ConfigParser import grp import logging import os +import json import platform import socket @@ -116,8 +117,8 @@ def check_or_create_default_vpnconf(config): 'remote_ip') validate_ip(remote_ip) - except ConfigParser.NoOptionError: - raise EIPInitNoProviderError + except ConfigParser.NoSectionError: + raise eip_exceptions.EIPInitNoProviderError except socket.error: # this does not look like an ip, dave @@ -402,7 +403,7 @@ def check_vpn_keys(config): if not os.path.isfile(keyfile): logger.error('key file %s not found. aborting.', keyfile) - raise EIPInitNoKeyFileError + raise eip_exceptions.EIPInitNoKeyFileError # check proper permission on keys # bad perms? try to fix them @@ -410,3 +411,27 @@ def check_vpn_keys(config): check_and_fix_urw_only(keyfile) except OSError: raise EIPInitBadKeyFilePermError + + +def get_config_json(config_file=None): + """ + will replace get_config function be developing them + in parralel for branch purposes. + @param: configuration file + @type: file + @rparam: configuration turples + @rtype: dictionary + """ + if not config_file: + fpath = get_config_file('eip.json') + if not os.path.isfile(fpath): + dpath, cfile = os.path.split(fpath) + if not os.path.isdir(dpath): + mkdir_p(dpath) + with open(fpath, 'wb') as configfile: + configfile.flush() + config_file = open(fpath) + + config = json.load(config_file) + + return config diff --git a/src/leap/eip/tests/tests_config.py b/src/leap/eip/tests/tests_config.py new file mode 100644 index 00000000..5a0e2d94 --- /dev/null +++ b/src/leap/eip/tests/tests_config.py @@ -0,0 +1,19 @@ + +"""Test config helper functions""" + +import unittest + +from leap.eip import config + + +class TestConfig(unittest.TestCase): + """ + Test configuration help functions. + """ + + def test_get_config_json(self): + config_js = config.get_config_json() + self.assertTrue(isinstance(config_js, dict)) + self.assertTrue('transport' in config_js) + self.assertTrue('provider' in config_js) + self.assertEqual(config_js['provider'], "testprovider.org") |