diff options
author | Tomás Touceda <chiiph@leap.se> | 2013-10-04 12:09:58 -0300 |
---|---|---|
committer | Tomás Touceda <chiiph@leap.se> | 2013-10-04 12:09:58 -0300 |
commit | 584866689560bd2ebea01ecc5e6ae5e79ce7fc81 (patch) | |
tree | 4fe300c3c105e17721f79eeece9bbd3745b43d78 /src/leap/bitmask/services/eip/eipconfig.py | |
parent | 1f0f8efc4cb985c082b3b8fe7b3dc45aed047a47 (diff) | |
parent | 759d73ae0728f074e0fb0740269249d0e5066574 (diff) |
Merge branch 'release-0.3.4'0.3.4
Diffstat (limited to 'src/leap/bitmask/services/eip/eipconfig.py')
-rw-r--r-- | src/leap/bitmask/services/eip/eipconfig.py | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/leap/bitmask/services/eip/eipconfig.py b/src/leap/bitmask/services/eip/eipconfig.py index 7d8995b4..16ed4cc0 100644 --- a/src/leap/bitmask/services/eip/eipconfig.py +++ b/src/leap/bitmask/services/eip/eipconfig.py @@ -33,6 +33,45 @@ from leap.common.check import leap_assert, leap_assert_type logger = logging.getLogger(__name__) +def get_eipconfig_path(domain): + """ + Returns relative path for EIP config. + + :param domain: the domain to which this eipconfig belongs to. + :type domain: str + :returns: the path + :rtype: str + """ + leap_assert(domain is not None, "get_eipconfig_path: We need a domain") + return os.path.join("leap", "providers", domain, "eip-service.json") + + +def load_eipconfig_if_needed(provider_config, eip_config, domain): + """ + Utility function to prime a eip_config object from a loaded + provider_config and the chosen provider domain. + + :param provider_config: a loaded instance of ProviderConfig + :type provider_config: ProviderConfig + + :param eip_config: the eipconfig object to be primed. + :type eip_config: EIPConfig + + :param domain: the chosen provider domain + :type domain: str + + :returns: Whether the eip_config object has been succesfully loaded + :rtype: bool + """ + loaded = eip_config.loaded() + if not loaded: + eip_config_path = get_eipconfig_path(domain) + api_version = provider_config.get_api_version() + eip_config.set_api_version(api_version) + loaded = eip_config.load(eip_config_path) + return loaded + + class VPNGatewaySelector(object): """ VPN Gateway selector. @@ -59,7 +98,6 @@ class VPNGatewaySelector(object): tz_offset = self.equivalent_timezones[tz_offset] self._local_offset = tz_offset - self._eipconfig = eipconfig def get_gateways_list(self): |