From baf3738bec7a712f90316f79255d4c91259e3fdf Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Tue, 6 Aug 2013 18:04:38 -0300 Subject: Add multiple schemas support for SMTP --- src/leap/services/mail/smtpspec.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/leap/services/mail/smtpspec.py b/src/leap/services/mail/smtpspec.py index 270dfb76..9fc1984a 100644 --- a/src/leap/services/mail/smtpspec.py +++ b/src/leap/services/mail/smtpspec.py @@ -15,7 +15,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -smtp_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 +smtp_config_spec = {} + +smtp_config_spec['1'] = { 'description': 'sample smtp service config', 'type': 'object', 'properties': { @@ -49,3 +56,15 @@ smtp_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 = smtp_config_spec.get(version, None) + return schema -- cgit v1.2.3 From 4ee2773660a571b180732ef41446399edf8501ac Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Tue, 6 Aug 2013 18:05:06 -0300 Subject: Update code to use the new SMTP schema selection. --- src/leap/services/mail/smtpbootstrapper.py | 8 ++++++-- src/leap/services/mail/smtpconfig.py | 9 ++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/leap/services/mail/smtpbootstrapper.py b/src/leap/services/mail/smtpbootstrapper.py index e8af5349..48040035 100644 --- a/src/leap/services/mail/smtpbootstrapper.py +++ b/src/leap/services/mail/smtpbootstrapper.py @@ -72,10 +72,12 @@ class SMTPBootstrapper(AbstractBootstrapper): if self._download_if_needed and mtime: headers['if-modified-since'] = mtime + api_version = self._provider_config.get_api_version() + # there is some confusion with this uri, config_uri = "%s/%s/config/smtp-service.json" % ( - self._provider_config.get_api_uri(), - self._provider_config.get_api_version()) + self._provider_config.get_api_uri(), api_version) + logger.debug('Downloading SMTP config from: %s' % config_uri) srp_auth = SRPAuth(self._provider_config) @@ -91,6 +93,8 @@ class SMTPBootstrapper(AbstractBootstrapper): cookies=cookies) res.raise_for_status() + self._smtp_config.set_api_version(api_version) + # Not modified if res.status_code == 304: logger.debug("SMTP definition has not been modified") diff --git a/src/leap/services/mail/smtpconfig.py b/src/leap/services/mail/smtpconfig.py index 30371005..ca974fcf 100644 --- a/src/leap/services/mail/smtpconfig.py +++ b/src/leap/services/mail/smtpconfig.py @@ -21,7 +21,7 @@ SMTP configuration import logging from leap.common.config.baseconfig import BaseConfig -from leap.services.mail.smtpspec import smtp_config_spec +from leap.services.mail.smtpspec import get_schema logger = logging.getLogger(__name__) @@ -33,12 +33,7 @@ class SMTPConfig(BaseConfig): def __init__(self): BaseConfig.__init__(self) - - def _get_spec(self): - """ - Returns the spec object for the specific configuration - """ - return smtp_config_spec + self._get_schema = get_schema def get_hosts(self): return self._safe_get_value("hosts") -- cgit v1.2.3 From 088db436880edd8c8ae51f792fc707d962927485 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Tue, 6 Aug 2013 18:05:25 -0300 Subject: Move code to common.BaseConfig --- src/leap/services/eip/eipconfig.py | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/leap/services/eip/eipconfig.py b/src/leap/services/eip/eipconfig.py index 2f2f6e7c..da44c3a6 100644 --- a/src/leap/services/eip/eipconfig.py +++ b/src/leap/services/eip/eipconfig.py @@ -137,26 +137,7 @@ 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 - """ - 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, )) + self._get_schema = get_schema def get_clusters(self): # TODO: create an abstraction for clusters -- cgit v1.2.3 From 959c24f3eae90f5b306aa99401bc11c5021b0faa Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 7 Aug 2013 14:50:16 -0300 Subject: Define abstract methods from BaseConfig. --- src/leap/services/eip/eipconfig.py | 9 ++++++++- src/leap/services/mail/smtpconfig.py | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/leap/services/eip/eipconfig.py b/src/leap/services/eip/eipconfig.py index da44c3a6..d69e1fd8 100644 --- a/src/leap/services/eip/eipconfig.py +++ b/src/leap/services/eip/eipconfig.py @@ -137,7 +137,14 @@ class EIPConfig(BaseConfig): def __init__(self): BaseConfig.__init__(self) self._api_version = None - self._get_schema = get_schema + + def _get_schema(self): + """ + Returns the schema corresponding to the version given. + + :rtype: dict or None if the version is not supported. + """ + return get_schema(self._api_version) def get_clusters(self): # TODO: create an abstraction for clusters diff --git a/src/leap/services/mail/smtpconfig.py b/src/leap/services/mail/smtpconfig.py index ca974fcf..ea0f9c37 100644 --- a/src/leap/services/mail/smtpconfig.py +++ b/src/leap/services/mail/smtpconfig.py @@ -33,7 +33,14 @@ class SMTPConfig(BaseConfig): def __init__(self): BaseConfig.__init__(self) - self._get_schema = get_schema + + def _get_schema(self): + """ + Returns the schema corresponding to the version given. + + :rtype: dict or None if the version is not supported. + """ + return get_schema(self._api_version) def get_hosts(self): return self._safe_get_value("hosts") -- cgit v1.2.3 From 52d33ab34cfdb9464b25101843dba3b221aa3b45 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 7 Aug 2013 11:51:54 -0300 Subject: Add changelog for #3403. --- changes/feature-3403_support-multiple-schemas | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/feature-3403_support-multiple-schemas diff --git a/changes/feature-3403_support-multiple-schemas b/changes/feature-3403_support-multiple-schemas new file mode 100644 index 00000000..9ed7ac89 --- /dev/null +++ b/changes/feature-3403_support-multiple-schemas @@ -0,0 +1 @@ + o Add multiple schema support for SMTP. Closes #3403. -- cgit v1.2.3