changeset 380:e81964db3cd6

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.
author Goffi <goffi@goffi.org>
date Sun, 13 Jan 2019 18:56:17 +0100
parents 66fbf026ed49
children 7c490bb60847
files src/backend.py src/twisted/plugins/pubsub.py
diffstat 2 files changed, 28 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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)