diff options
author | kali <kali@leap.se> | 2012-08-30 03:43:05 +0900 |
---|---|---|
committer | kali <kali@leap.se> | 2012-08-30 03:43:05 +0900 |
commit | d69976caa5070403f81799c79be974241cff7f70 (patch) | |
tree | 6f2e7820a3eed1bf5f200b4043d7d89cb8b6a302 /src/leap/eip/checks.py | |
parent | e6483d20a5500e86b5fa4e7da63f911641b7e9dd (diff) |
fetcher moved to baseconfig + eipchecker using eipservice config.
Diffstat (limited to 'src/leap/eip/checks.py')
-rw-r--r-- | src/leap/eip/checks.py | 76 |
1 files changed, 24 insertions, 52 deletions
diff --git a/src/leap/eip/checks.py b/src/leap/eip/checks.py index 4b2326a5..b57977f0 100644 --- a/src/leap/eip/checks.py +++ b/src/leap/eip/checks.py @@ -8,12 +8,11 @@ logger.setLevel(logging.DEBUG) import requests -from leap.base import config as baseconfig from leap.base import constants as baseconstants +from leap.base import providers from leap.eip import config as eipconfig from leap.eip import constants as eipconstants from leap.eip import exceptions as eipexceptions -from leap.util.fileutil import mkdir_p """ EIPConfigChecker @@ -49,10 +48,11 @@ class EIPConfigChecker(object): # argument on init. # we want tests # to be explicitely run. - self.config = None self.fetcher = fetcher self.eipconfig = eipconfig.EIPConfig() + self.defaultprovider = providers.LeapProviderDefinition() + self.eipserviceconfig = eipconfig.EIPServiceConfig() def run_all(self, checker=None, skip_download=False): """ @@ -74,7 +74,7 @@ class EIPConfigChecker(object): checker.check_is_there_default_provider() checker.fetch_definition(skip_download=skip_download) - checker.fetch_eip_config(skip_download=skip_download) + checker.fetch_eip_service_config(skip_download=skip_download) checker.check_complete_eip_config() #checker.ping_gateway() @@ -109,8 +109,7 @@ class EIPConfigChecker(object): provider = config.get('provider', None) if provider is None: raise eipexceptions.EIPMissingDefaultProvider - if config: - self.config = config + # XXX raise also if malformed ProviderDefinition? return True def fetch_definition(self, skip_download=False, @@ -120,65 +119,38 @@ class EIPConfigChecker(object): """ # TODO: # - Implement diff - # - overwrite if different. + # - overwrite only if different. + # (attend to serial field different, for instance) + logger.debug('fetching definition') if skip_download: logger.debug('(fetching def skipped)') return True if config is None: - config = self.config + config = self.defaultprovider.get_config() if uri is None: - if config: - domain = config.get('provider', None) - else: - domain = None - uri = self._get_provider_definition_uri( - domain=domain) - - # XXX move to JSONConfig Fetcher - request = self.fetcher.get(uri) - request.raise_for_status() - - definition_file = os.path.join( - baseconfig.get_default_provider_path(), - baseconstants.DEFINITION_EXPECTED_PATH) - - folder, filename = os.path.split(definition_file) - if not os.path.isdir(folder): - mkdir_p(folder) - with open(definition_file, 'wb') as f: - f.write(json.dumps(request.json, indent=4)) - - def fetch_eip_config(self, skip_download=False, - config=None, uri=None): + domain = config.get('provider', None) + uri = self._get_provider_definition_uri(domain=domain) + + self.defaultprovider.load(from_uri=uri, fetcher=self.fetcher) + self.defaultprovider.save() + + def fetch_eip_service_config(self, skip_download=False, + config=None, uri=None): if skip_download: return True if config is None: - config = self.config + config = self.eipserviceconfig.get_config() if uri is None: - if config: - domain = config.get('provider', None) - else: - domain = None - uri = self._get_eip_service_uri( - domain=domain) - - # XXX move to JSONConfig Fetcher - request = self.fetcher.get(uri) - request.raise_for_status() - - definition_file = os.path.join( - baseconfig.get_default_provider_path(), - eipconstants.EIP_SERVICE_EXPECTED_PATH) - - folder, filename = os.path.split(definition_file) - if not os.path.isdir(folder): - mkdir_p(folder) - with open(definition_file, 'wb') as f: - f.write(json.dumps(request.json, indent=4)) + domain = config.get('provider', None) + uri = self._get_eip_service_uri(domain=domain) + + self.eipserviceconfig.load(from_uri=uri, fetcher=self.fetcher) + self.eipserviceconfig.save() def check_complete_eip_config(self, config=None): + # TODO check for gateway if config is None: config = self.config try: |