From 92957c4b666d6e5fc54275d8857692a12b0fb209 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Wed, 1 Mar 2017 19:32:54 +0100 Subject: [feat] get VPN params from eip-service.json Instead of hardcoding them in the code. --- src/leap/bitmask/bonafide/_protocol.py | 4 ++++ src/leap/bitmask/bonafide/config.py | 18 ++++++++++++++---- src/leap/bitmask/bonafide/service.py | 4 +++- 3 files changed, 21 insertions(+), 5 deletions(-) (limited to 'src/leap/bitmask/bonafide') diff --git a/src/leap/bitmask/bonafide/_protocol.py b/src/leap/bitmask/bonafide/_protocol.py index 91b8b24..391aa8d 100644 --- a/src/leap/bitmask/bonafide/_protocol.py +++ b/src/leap/bitmask/bonafide/_protocol.py @@ -177,6 +177,10 @@ class BonafideProtocol(object): provider = config.Provider(provider_id, autoconf=autoconf) return provider.callWhenMainConfigReady(provider.config) + def do_get_service(self, provider_id, service, autoconf=False): + provider = config.Provider(provider_id, autoconf=autoconf) + return provider.callWhenMainConfigReady(provider.config, service) + def do_provider_delete(self, provider_id): return config.delete_provider(provider_id) diff --git a/src/leap/bitmask/bonafide/config.py b/src/leap/bitmask/bonafide/config.py index ba45465..1002edb 100644 --- a/src/leap/bitmask/bonafide/config.py +++ b/src/leap/bitmask/bonafide/config.py @@ -234,10 +234,20 @@ class Provider(object): return False return True - def config(self): - if not self._provider_config: - self._load_provider_json() - return self._provider_config.dict() + def config(self, service=None): + if not service: + if not self._provider_config: + self._load_provider_json() + return self._provider_config.dict() + + path = self._get_service_config_path(service) + try: + with open(path, 'r') as config: + config = Record(**json.load(config)) + except IOError: + raise ValueError("Service " + service + + " not found in provider " + self._domain) + return config def bootstrap(self): domain = self._domain diff --git a/src/leap/bitmask/bonafide/service.py b/src/leap/bitmask/bonafide/service.py index dc57917..0a78813 100644 --- a/src/leap/bitmask/bonafide/service.py +++ b/src/leap/bitmask/bonafide/service.py @@ -111,7 +111,9 @@ class BonafideService(HookableService): def do_provider_create(self, domain): return self._bonafide.do_get_provider(domain, autoconf=True) - def do_provider_read(self, domain): + def do_provider_read(self, domain, service=None): + if service: + return self._bonafide.do_get_service(domain, service) return self._bonafide.do_get_provider(domain) def do_provider_delete(self, domain): -- cgit v1.2.3