# HG changeset patch # User Goffi # Date 1547402177 -3600 # Node ID e81964db3cd6fb6474971343e3f89ac0a34036a2 # Parent 66fbf026ed492035fefe5123944cc9034ced198a administrators entities: In config file, the "admins_jids_list" setting can now be set to give a list of bare jids of entities with administrator privileges. This is not used yet but will be soon. config is now available in backend using self.config. diff -r 66fbf026ed49 -r e81964db3cd6 src/backend.py --- a/src/backend.py Sat Jan 12 16:43:46 2019 +0100 +++ b/src/backend.py Sun Jan 13 18:56:17 2019 +0100 @@ -163,10 +163,11 @@ }, } - def __init__(self, storage): + def __init__(self, storage, config): utility.EventDispatcher.__init__(self) self.storage = storage self._callbackList = [] + self.config = config def supportsPublishOptions(self): return True diff -r 66fbf026ed49 -r e81964db3cd6 src/twisted/plugins/pubsub.py --- a/src/twisted/plugins/pubsub.py Sat Jan 12 16:43:46 2019 +0100 +++ b/src/twisted/plugins/pubsub.py Sun Jan 13 18:56:17 2019 +0100 @@ -50,10 +50,12 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +import csv import sat_pubsub +import sys from twisted.application.service import IServiceMaker from twisted.application import service -from twisted.python import usage +from twisted.python import usage, log from twisted.words.protocols.jabber.jid import JID from twisted.plugin import IPlugin @@ -77,6 +79,20 @@ import ConfigParser +def coerceListType(value): + return csv.reader( + [value], delimiter=",", quotechar='"', skipinitialspace=True + ).next() + + +def coerceJidListType(value): + values = [JID(v) for v in coerceListType(value)] + if any((j.resource for j in values)): + raise ValueError(u"you must use bare jids") + return values + + + OPT_PARAMETERS_BOTH = [ ['jid', None, None, 'JID this component will be available at'], ['xmpp_pwd', None, None, 'XMPP server component password'], @@ -90,7 +106,10 @@ ['db_port', None, None, 'Database port (pgsql backend)'], ] # here for future use -OPT_PARAMETERS_CFG = [] +OPT_PARAMETERS_CFG = [ + ["admins_jids_list", None, [], "List of administrators' bare jids", + coerceJidListType] + ] CONFIG_FILENAME = u'sat' # List of the configuration filenames sorted by ascending priority @@ -134,6 +153,10 @@ param[2] = param[4](value) except IndexError: # the coerce method is optional param[2] = value + except Exception as e: + log.err(u'Invalid value for setting "{name}": {msg}'.format( + name=name, msg=e)) + sys.exit(1) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): pass usage.Options.__init__(self) @@ -190,7 +213,7 @@ from sat_pubsub.memory_storage import Storage st = Storage() - bs = BackendService(st) + bs = BackendService(st, config) bs.setName('backend') bs.setServiceParent(s)