summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changes/feature-3310_support-multiple-schemas1
-rw-r--r--src/leap/gui/mainwindow.py39
-rw-r--r--src/leap/services/eip/eipbootstrapper.py4
-rw-r--r--src/leap/services/eip/eipconfig.py21
-rw-r--r--src/leap/services/eip/eipspec.py22
-rw-r--r--src/leap/services/eip/tests/test_eipconfig.py17
-rw-r--r--src/leap/services/eip/vpnlaunchers.py1
7 files changed, 80 insertions, 25 deletions
diff --git a/changes/feature-3310_support-multiple-schemas b/changes/feature-3310_support-multiple-schemas
new file mode 100644
index 00000000..d5471507
--- /dev/null
+++ b/changes/feature-3310_support-multiple-schemas
@@ -0,0 +1 @@
+ o Add support for multiple schemas so we can support multiples api versions. Closes #3310.
diff --git a/src/leap/gui/mainwindow.py b/src/leap/gui/mainwindow.py
index 87dd4f5c..39160db9 100644
--- a/src/leap/gui/mainwindow.py
+++ b/src/leap/gui/mainwindow.py
@@ -1222,29 +1222,34 @@ class MainWindow(QtGui.QMainWindow):
loaded
"""
leap_assert(self._eip_config, "We need an eip config!")
+ passed = data[self._eip_bootstrapper.PASSED_KEY]
+
+ if not passed:
+ error_msg = self.tr("There was a problem with the provider")
+ self._status_panel.set_eip_status(error_msg, error=True)
+ logger.error(data[self._eip_bootstrapper.ERROR_KEY])
+ self._already_started_eip = False
+ return
provider_config = self._get_best_provider_config()
domain = provider_config.get_domain()
- if data[self._eip_bootstrapper.PASSED_KEY] and \
- (self._eip_config.loaded() or
- self._eip_config.load(os.path.join("leap",
- "providers",
- domain,
- "eip-service.json"))):
- self._start_eip()
+ loaded = self._eip_config.loaded()
+ if not loaded:
+ eip_config_path = os.path.join("leap", "providers",
+ domain, "eip-service.json")
+ api_version = provider_config.get_api_version()
+ self._eip_config.set_api_version(api_version)
+ loaded = self._eip_config.load(eip_config_path)
+
+ if loaded:
+ self._start_eip()
else:
- if data[self._eip_bootstrapper.PASSED_KEY]:
- self._status_panel.set_eip_status(
- self.tr("Could not load Encrypted Internet "
- "Configuration."),
- error=True)
- else:
- self._status_panel.set_eip_status(
- data[self._eip_bootstrapper.ERROR_KEY],
- error=True)
- self._already_started_eip = False
+ self._status_panel.set_eip_status(
+ self.tr("Could not load Encrypted Internet "
+ "Configuration."),
+ error=True)
def _logout(self):
"""
diff --git a/src/leap/services/eip/eipbootstrapper.py b/src/leap/services/eip/eipbootstrapper.py
index 60270b5b..1d7bc342 100644
--- a/src/leap/services/eip/eipbootstrapper.py
+++ b/src/leap/services/eip/eipbootstrapper.py
@@ -67,7 +67,9 @@ class EIPBootstrapper(AbstractBootstrapper):
logger.debug("Downloading EIP config for %s" %
(self._provider_config.get_domain(),))
+ api_version = self._provider_config.get_api_version()
self._eip_config = EIPConfig()
+ self._eip_config.set_api_version(api_version)
headers = {}
mtime = get_mtime(os.path.join(self._eip_config
@@ -84,7 +86,7 @@ class EIPBootstrapper(AbstractBootstrapper):
# it's in 1/config/eip, config/eip and config/1/eip...
config_uri = "%s/%s/config/eip-service.json" % (
self._provider_config.get_api_uri(),
- self._provider_config.get_api_version())
+ api_version)
logger.debug('Downloading eip config from: %s' % config_uri)
res = self._session.get(config_uri,
diff --git a/src/leap/services/eip/eipconfig.py b/src/leap/services/eip/eipconfig.py
index 9e3a9b29..2f2f6e7c 100644
--- a/src/leap/services/eip/eipconfig.py
+++ b/src/leap/services/eip/eipconfig.py
@@ -28,7 +28,7 @@ import ipaddr
from leap.common.check import leap_assert, leap_assert_type
from leap.common.config.baseconfig import BaseConfig
from leap.config.providerconfig import ProviderConfig
-from leap.services.eip.eipspec import eipservice_config_spec
+from leap.services.eip.eipspec import get_schema
logger = logging.getLogger(__name__)
@@ -136,12 +136,27 @@ class EIPConfig(BaseConfig):
def __init__(self):
BaseConfig.__init__(self)
+ self._api_version = None
def _get_spec(self):
"""
Returns the spec object for the specific configuration
"""
- return eipservice_config_spec
+ leap_assert(self._api_version is not None,
+ "You should set the API version.")
+
+ return get_schema(self._api_version)
+
+ def set_api_version(self, version):
+ """
+ Sets the supported api version.
+
+ :param api_version: the version of the api supported by the provider.
+ :type api_version: str
+ """
+ self._api_version = version
+ leap_assert(get_schema(self._api_version) is not None,
+ "Version %s is not supported." % (version, ))
def get_clusters(self):
# TODO: create an abstraction for clusters
@@ -243,7 +258,7 @@ if __name__ == "__main__":
console.setFormatter(formatter)
logger.addHandler(console)
- eipconfig = EIPConfig()
+ eipconfig = EIPConfig('1')
try:
eipconfig.get_clusters()
diff --git a/src/leap/services/eip/eipspec.py b/src/leap/services/eip/eipspec.py
index 94ba674f..9cc56be3 100644
--- a/src/leap/services/eip/eipspec.py
+++ b/src/leap/services/eip/eipspec.py
@@ -15,7 +15,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-eipservice_config_spec = {
+
+# Schemas dict
+# To add a schema for a version you should follow the form:
+# { '1': schema_v1, '2': schema_v2, ... etc }
+# so for instance, to add the '2' version, you should do:
+# eipservice_config_spec['2'] = schema_v2
+eipservice_config_spec = {}
+
+eipservice_config_spec['1'] = {
'description': 'sample eip service config',
'type': 'object',
'properties': {
@@ -63,3 +71,15 @@ eipservice_config_spec = {
}
}
}
+
+
+def get_schema(version):
+ """
+ Returns the schema corresponding to the version given.
+
+ :param version: the version of the schema to get.
+ :type version: str
+ :rtype: dict or None if the version is not supported.
+ """
+ schema = eipservice_config_spec.get(version, None)
+ return schema
diff --git a/src/leap/services/eip/tests/test_eipconfig.py b/src/leap/services/eip/tests/test_eipconfig.py
index 8b746b78..87ce04c2 100644
--- a/src/leap/services/eip/tests/test_eipconfig.py
+++ b/src/leap/services/eip/tests/test_eipconfig.py
@@ -117,18 +117,21 @@ class EIPConfigTest(BaseLeapTest):
conf.write(json.dumps(data))
conf.close()
- def _get_eipconfig(self, fromfile=True, data=sample_config):
+ def _get_eipconfig(self, fromfile=True, data=sample_config, api_ver='1'):
"""
Helper that returns an EIPConfig object using the data parameter
or a sample data.
:param fromfile: sets if we should use a file or a string
- :fromfile type: bool
+ :type fromfile: bool
:param data: sets the data to be used to load in the EIPConfig object
- :data type: dict (valid json)
+ :type data: dict (valid json)
+ :param api_ver: the api_version schema to use.
+ :type api_ver: str
:rtype: EIPConfig
"""
config = EIPConfig()
+ config.set_api_version(api_ver)
loaded = False
if fromfile:
@@ -308,6 +311,14 @@ class EIPConfigTest(BaseLeapTest):
with self.assertRaises(AssertionError):
config.get_client_cert_path(provider_config)
+ def test_fails_without_api_set(self):
+ config = EIPConfig()
+ with self.assertRaises(AssertionError):
+ config.load('non-relevant-path')
+
+ def test_fails_with_api_without_schema(self):
+ with self.assertRaises(AssertionError):
+ self._get_eipconfig(api_ver='123')
if __name__ == "__main__":
unittest.main()
diff --git a/src/leap/services/eip/vpnlaunchers.py b/src/leap/services/eip/vpnlaunchers.py
index 0151c1c6..526f1ba4 100644
--- a/src/leap/services/eip/vpnlaunchers.py
+++ b/src/leap/services/eip/vpnlaunchers.py
@@ -903,6 +903,7 @@ if __name__ == "__main__":
vpnlauncher = get_platform_launcher()
eipconfig = EIPConfig()
+ eipconfig.set_api_version('1')
if eipconfig.load("leap/providers/bitmask.net/eip-service.json"):
provider = ProviderConfig()
if provider.load("leap/providers/bitmask.net/provider.json"):