summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG6
-rw-r--r--setup.py2
-rw-r--r--src/leap/common/__init__.py2
-rw-r--r--src/leap/common/config/baseconfig.py42
-rw-r--r--src/leap/common/config/prefixers.py2
5 files changed, 48 insertions, 6 deletions
diff --git a/CHANGELOG b/CHANGELOG
index a66674b..81c5f96 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,9 @@
+0.3.0 Aug 9:
+ o OSX: Fix problem with path prefix not returning the correct
+ value. Fixes #3273.
+ o Check if schema exists before load a config. Related to #3310.
+ o Handle schemas and api versions in base class. Related to #3310.
+
0.2.7 Jul 26:
o Refactor events so components are now called clients. Closes #3246
o Add leap_check helper method, to use whenever leap_assert does not
diff --git a/setup.py b/setup.py
index 43848d0..0db731e 100644
--- a/setup.py
+++ b/setup.py
@@ -56,7 +56,7 @@ setup(
name='leap.common',
# If you change version, do it also in
# src/leap/common/__init__.py
- version='0.2.7',
+ version='0.3.0',
url='https://leap.se/',
license='GPLv3+',
author='The LEAP Encryption Access Project',
diff --git a/src/leap/common/__init__.py b/src/leap/common/__init__.py
index b378d5e..3946fe8 100644
--- a/src/leap/common/__init__.py
+++ b/src/leap/common/__init__.py
@@ -16,4 +16,4 @@ except ImportError:
__all__ = ["certs", "check", "files", "events"]
-__version__ = "0.2.7"
+__version__ = "0.3.0"
diff --git a/src/leap/common/config/baseconfig.py b/src/leap/common/config/baseconfig.py
index 699d734..e310bc0 100644
--- a/src/leap/common/config/baseconfig.py
+++ b/src/leap/common/config/baseconfig.py
@@ -26,7 +26,7 @@ import os
from abc import ABCMeta, abstractmethod
-from leap.common.check import leap_assert
+from leap.common.check import leap_assert, leap_check
from leap.common.files import mkdir_p
from leap.common.config.pluggableconfig import PluggableConfig
from leap.common.config.prefixers import get_platform_prefixer
@@ -34,6 +34,12 @@ from leap.common.config.prefixers import get_platform_prefixer
logger = logging.getLogger(__name__)
+class NonExistingSchema(Exception):
+ """
+ Raised if the schema needed to verify the config is None.
+ """
+
+
class BaseConfig:
"""
Abstract base class for any JSON based configuration.
@@ -55,13 +61,27 @@ class BaseConfig:
def __init__(self):
self._data = {}
self._config_checker = None
+ self._api_version = None
@abstractmethod
+ def _get_schema(self):
+ """
+ Returns the schema corresponding to the version given.
+
+ :rtype: dict or None if the version is not supported.
+ """
+ pass
+
def _get_spec(self):
"""
Returns the spec object for the specific configuration.
+
+ :rtype: dict or None if the version is not supported.
"""
- return None
+ leap_assert(self._api_version is not None,
+ "You should set the API version.")
+
+ return self._get_schema()
def _safe_get_value(self, key):
"""
@@ -73,6 +93,17 @@ class BaseConfig:
leap_assert(self._config_checker, "Load the config first")
return self._config_checker.config.get(key, None)
+ 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(self._get_schema() is not None,
+ "Version %s is not supported." % (version, ))
+
def get_path_prefix(self):
"""
Returns the platform dependant path prefixer
@@ -112,6 +143,7 @@ class BaseConfig:
def load(self, path="", data=None, mtime=None, relative=True):
"""
Loads the configuration from disk.
+ It may raise NonExistingSchema exception.
:param path: if relative=True, this is a relative path
to configuration. The absolute path
@@ -131,8 +163,12 @@ class BaseConfig:
else:
config_path = path
+ schema = self._get_spec()
+ leap_check(schema is not None,
+ "There is no schema to use.", NonExistingSchema)
+
self._config_checker = PluggableConfig(format="json")
- self._config_checker.options = copy.deepcopy(self._get_spec())
+ self._config_checker.options = copy.deepcopy(schema)
try:
if data is None:
diff --git a/src/leap/common/config/prefixers.py b/src/leap/common/config/prefixers.py
index 050d4cd..9a5b043 100644
--- a/src/leap/common/config/prefixers.py
+++ b/src/leap/common/config/prefixers.py
@@ -95,7 +95,7 @@ class DarwinPrefixer(Prefixer):
config_dir = BaseDirectory.xdg_config_home
if not standalone:
return config_dir
- return os.getenv(os.getcwd(), "config")
+ return os.path.join(os.getcwd(), "config")
class WindowsPrefixer(Prefixer):