diff options
Diffstat (limited to 'src/leap/services/mail')
-rw-r--r-- | src/leap/services/mail/smtpbootstrapper.py | 8 | ||||
-rw-r--r-- | src/leap/services/mail/smtpconfig.py | 10 | ||||
-rw-r--r-- | src/leap/services/mail/smtpspec.py | 21 |
3 files changed, 32 insertions, 7 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..ea0f9c37 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__) @@ -34,11 +34,13 @@ class SMTPConfig(BaseConfig): def __init__(self): BaseConfig.__init__(self) - def _get_spec(self): + def _get_schema(self): """ - Returns the spec object for the specific configuration + Returns the schema corresponding to the version given. + + :rtype: dict or None if the version is not supported. """ - return smtp_config_spec + return get_schema(self._api_version) def get_hosts(self): return self._safe_get_value("hosts") 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 <http://www.gnu.org/licenses/>. -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 |