Commit 5b1c006c authored by Denis Laxalde's avatar Denis Laxalde
Browse files

[server] Inline _entity_update method into init method of AbstractSource

This _entity_update method does not make sense now that we do not update
source from database information but always build them afresh.

--HG--
branch : 3.25
parent a446124bcf3c
......@@ -176,14 +176,6 @@ class AbstractSource(object):
return cls.check_conf_dict(source_entity.eid, source_entity.host_config,
_=source_entity._cw._)
def _entity_update(self, source_entity):
source_entity.complete()
if source_entity.url:
self.urls = [url.strip() for url in source_entity.url.splitlines()
if url.strip()]
else:
self.urls = []
# source initialization / finalization #####################################
def set_schema(self, schema):
......@@ -198,8 +190,14 @@ class AbstractSource(object):
"""method called by the repository once ready to handle request.
`activated` is a boolean flag telling if the source is activated or not.
"""
if activated:
self._entity_update(source_entity)
if not activated:
return
source_entity.complete()
if source_entity.url:
self.urls = [url.strip() for url in source_entity.url.splitlines()
if url.strip()]
else:
self.urls = []
PUBLIC_KEYS = ('type', 'uri', 'use-cwuri-as-url')
def remove_sensitive_information(self, sourcedef):
......
......@@ -107,14 +107,10 @@ class DataFeedSource(AbstractSource):
raise ValidationError(source_entity.eid, {'config': msg})
return typed_config
def _entity_update(self, source_entity):
super(DataFeedSource, self)._entity_update(source_entity)
self.parser_id = source_entity.parser
self.latest_retrieval = source_entity.latest_retrieval
def init(self, activated, source_entity):
super(DataFeedSource, self).init(activated, source_entity)
self.parser_id = source_entity.parser
self.latest_retrieval = source_entity.latest_retrieval
typed_config = self.config
self.synchro_interval = timedelta(seconds=typed_config['synchronization-interval'])
self.max_lock_lifetime = timedelta(seconds=typed_config['max-lock-lifetime'])
......
......@@ -178,6 +178,16 @@ You can set multiple groups by separating them by a comma.',
def init(self, activated, source_entity):
super(LDAPFeedSource, self).init(activated, source_entity)
if self.urls:
if len(self.urls) > 1:
raise ValidationError(source_entity.eid, {'url': _('can only have one url')})
try:
protocol, hostport = self.urls[0].split('://')
except ValueError:
raise ValidationError(source_entity.eid, {'url': _('badly formatted url')})
if protocol not in PROTO_PORT:
raise ValidationError(source_entity.eid, {'url': _('unsupported protocol')})
typedconfig = self.config
self.authmode = typedconfig['auth-mode']
self._authenticate = getattr(self, '_auth_%s' % self.authmode)
......@@ -206,18 +216,6 @@ You can set multiple groups by separating them by a comma.',
self.group_base_filters.append(typedconfig['group-filter'])
self._conn = None
def _entity_update(self, source_entity):
super(LDAPFeedSource, self)._entity_update(source_entity)
if self.urls:
if len(self.urls) > 1:
raise ValidationError(source_entity.eid, {'url': _('can only have one url')})
try:
protocol, hostport = self.urls[0].split('://')
except ValueError:
raise ValidationError(source_entity.eid, {'url': _('badly formatted url')})
if protocol not in PROTO_PORT:
raise ValidationError(source_entity.eid, {'url': _('unsupported protocol')})
def connection_info(self):
assert len(self.urls) == 1, self.urls
protocol, hostport = self.urls[0].split('://')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment