diff options
author | kali <kali@leap.se> | 2012-08-29 23:05:38 +0900 |
---|---|---|
committer | kali <kali@leap.se> | 2012-08-29 23:05:38 +0900 |
commit | ed4ad3a392caf0211e51a48d2d7b6c5a2f7bb17a (patch) | |
tree | 55958957a27f3784aef99f122673852becb4c1c2 /src/leap/eip | |
parent | 63c0b7aa3ded55426a834d0a5947fff798894c6b (diff) |
add eipconfig spec and config object
Diffstat (limited to 'src/leap/eip')
-rw-r--r-- | src/leap/eip/checks.py | 5 | ||||
-rw-r--r-- | src/leap/eip/config.py | 47 | ||||
-rw-r--r-- | src/leap/eip/constants.py | 3 | ||||
-rw-r--r-- | src/leap/eip/specs.py | 64 | ||||
-rw-r--r-- | src/leap/eip/tests/test_config.py | 2 |
5 files changed, 101 insertions, 20 deletions
diff --git a/src/leap/eip/checks.py b/src/leap/eip/checks.py index 27320b1f..e5b8e971 100644 --- a/src/leap/eip/checks.py +++ b/src/leap/eip/checks.py @@ -52,6 +52,8 @@ class EIPConfigChecker(object): self.config = None self.fetcher = fetcher + #self.eipconfig = eipconfig.EIPConfig() + def run_all(self, checker=None, skip_download=False): """ runs all checks in a row. @@ -208,10 +210,13 @@ class EIPConfigChecker(object): return baseconfig.get_config_file(eipconstants.EIP_CONFIG) def _is_there_default_eipconfig(self): + #XXX + #self.eipconfig.exists() return os.path.isfile( self._get_default_eipconfig_path()) def _dump_default_eipconfig(self): + #XXX self.eipconfig.save() eipconfig.dump_default_eipconfig( self._get_default_eipconfig_path()) diff --git a/src/leap/eip/config.py b/src/leap/eip/config.py index 2694ca61..34f05070 100644 --- a/src/leap/eip/config.py +++ b/src/leap/eip/config.py @@ -8,20 +8,17 @@ import socket from leap.util.fileutil import (which, mkdir_p, check_and_fix_urw_only) -# from leap.base import config as baseconfig -from leap.base.config import (get_default_provider_path, - get_config_file, - get_username, - get_groupname, - validate_ip) +from leap.base import config as baseconfig from leap.baseapp.permcheck import (is_pkexec_in_system, is_auth_agent_running) from leap.eip import exceptions as eip_exceptions from leap.eip import constants as eipconstants +from leap.eip import specs as eipspecs logger = logging.getLogger(name=__name__) logger.setLevel('DEBUG') +# XXX deprecate per #447 OPENVPN_CONFIG_TEMPLATE = """#Autogenerated by eip-client wizard remote {VPN_REMOTE_HOST} {VPN_REMOTE_PORT} @@ -39,6 +36,18 @@ ca {LEAP_EIP_KEYS} """ +class EIPConfig(baseconfig.JSONLeapConfig): + spec = eipspecs.eipconfig_spec + + def _get_slug(self): + return baseconfig.get_config_file('eip.json') + + def _set_slug(self, *args, **kwargs): + raise AttributeError("you cannot set slug") + + slug = property(_get_slug, _set_slug) + + def check_or_create_default_vpnconf(config): """ checks that a vpn config file @@ -47,12 +56,12 @@ def check_or_create_default_vpnconf(config): ATM REQURES A [provider] section in eip.cfg with _at least_ a remote_ip value """ - default_provider_path = get_default_provider_path() + default_provider_path = baseconfig.get_default_provider_path() if not os.path.isdir(default_provider_path): mkdir_p(default_provider_path) - conf_file = get_config_file( + conf_file = baseconfig.get_config_file( 'openvpn.conf', folder=default_provider_path) @@ -74,7 +83,7 @@ def check_or_create_default_vpnconf(config): # and make a reverse resolv. remote_ip = config.get('provider', 'remote_ip') - validate_ip(remote_ip) + baseconfig.validate_ip(remote_ip) except ConfigParser.NoSectionError: raise eip_exceptions.EIPInitNoProviderError @@ -91,19 +100,19 @@ def check_or_create_default_vpnconf(config): default_subpath = os.path.join("providers", "default") - default_provider_path = get_config_file( + default_provider_path = baseconfig.get_config_file( '', folder=default_subpath) if not os.path.isdir(default_provider_path): mkdir_p(default_provider_path) - conf_file = get_config_file( + conf_file = baseconfig.get_config_file( 'openvpn.conf', folder=default_provider_path) # XXX keys have to be manually placed by now - keys_file = get_config_file( + keys_file = baseconfig.get_config_file( 'openvpn.keys', folder=default_provider_path) @@ -133,8 +142,8 @@ def build_ovpn_options(daemon=False): # get user/group name # also from config. - user = get_username() - group = get_groupname() + user = baseconfig.get_username() + group = baseconfig.get_groupname() opts = [] @@ -171,10 +180,10 @@ def build_ovpn_options(daemon=False): opts.append('--config') - default_provider_path = get_default_provider_path() + default_provider_path = baseconfig.get_default_provider_path() # XXX get rid of config_file at all - ovpncnf = get_config_file( + ovpncnf = baseconfig.get_config_file( 'openvpn.conf', folder=default_provider_path) opts.append(ovpncnf) @@ -296,7 +305,7 @@ def get_config(config_file=None): config = ConfigParser.ConfigParser(defaults) if not config_file: - fpath = get_config_file('eip.cfg') + fpath = baseconfig.get_config_file('eip.cfg') if not os.path.isfile(fpath): dpath, cfile = os.path.split(fpath) if not os.path.isdir(dpath): @@ -343,9 +352,9 @@ def check_vpn_keys(config): if config.has_option(*keyopt): keyfile = config.get(*keyopt) else: - keyfile = get_config_file( + keyfile = baseconfig.get_config_file( 'openvpn.keys', - folder=get_default_provider_path()) + folder=baseconfig.get_default_provider_path()) logger.debug('keyfile = %s', keyfile) # if no keys, raise error. diff --git a/src/leap/eip/constants.py b/src/leap/eip/constants.py index 6161d744..31974926 100644 --- a/src/leap/eip/constants.py +++ b/src/leap/eip/constants.py @@ -1,5 +1,8 @@ EIP_CONFIG = "eip.json" +# XXX deprecate. EIPConfig used instead +# can move for testing purposes. + EIP_SAMPLE_JSON = { "provider": "testprovider.example.org", "transport": "openvpn", diff --git a/src/leap/eip/specs.py b/src/leap/eip/specs.py new file mode 100644 index 00000000..572177dd --- /dev/null +++ b/src/leap/eip/specs.py @@ -0,0 +1,64 @@ +import os + +from leap.base import config as baseconfig + + +provider_ca_path = os.path.join( + baseconfig.get_default_provider_path(), + 'keys', 'ca', + 'testprovider-ca-cert.pem' +) + +client_cert_path = os.path.join( + baseconfig.get_default_provider_path(), + 'keys', 'client', + 'openvpn.pem' +) + +eipconfig_spec = { + 'provider': { + 'type': unicode, + 'default': u"testprovider.example.org", + 'required': True, + }, + 'transport': { + 'type': unicode, + 'default': u"openvpn", + }, + 'openvpn_protocol': { + 'type': unicode, + 'default': u"tcp" + }, + 'openvpn_port': { + 'type': int, + 'default': 80 + }, + 'oepnvpn_ca_certificate': { + 'type': unicode, # path + 'default': provider_ca_path + }, + 'openvpn_client_certificate': { + 'type': unicode, # path + 'default': client_cert_path + }, + 'connect_on_login': { + 'type': bool, + 'default': True + }, + 'block_cleartext_tr affic': { + 'type': bool, + 'default': True + }, + 'primary_gateway': { + 'type': unicode, + 'default': u"usa_west", + 'required': True + }, + 'secondary_gateway': { + 'type': unicode, + 'default': u"france" + }, + 'management_password': { + 'type': unicode + } +} diff --git a/src/leap/eip/tests/test_config.py b/src/leap/eip/tests/test_config.py index fac4729d..16219648 100644 --- a/src/leap/eip/tests/test_config.py +++ b/src/leap/eip/tests/test_config.py @@ -82,7 +82,7 @@ class EIPConfigTest(BaseLeapTest): self.assertEqual(args, self.get_expected_openvpn_args()) # XXX TODO: - # - should use touch_exec to plant an "executabe" in the path + # - should use touch_exec to plant an "executable" in the path # - should check that "which" for openvpn returns what's expected. |