comparison src/twisted/plugins/pubsub.py @ 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 9a787881b824
children 77b52dbda89a
comparison
equal deleted inserted replaced
379:66fbf026ed49 380:e81964db3cd6
48 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 48 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
49 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 49 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
50 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 50 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51 51
52 52
53 import csv
53 import sat_pubsub 54 import sat_pubsub
55 import sys
54 from twisted.application.service import IServiceMaker 56 from twisted.application.service import IServiceMaker
55 from twisted.application import service 57 from twisted.application import service
56 from twisted.python import usage 58 from twisted.python import usage, log
57 from twisted.words.protocols.jabber.jid import JID 59 from twisted.words.protocols.jabber.jid import JID
58 from twisted.plugin import IPlugin 60 from twisted.plugin import IPlugin
59 61
60 from wokkel.component import Component 62 from wokkel.component import Component
61 from wokkel.disco import DiscoHandler 63 from wokkel.disco import DiscoHandler
73 from sat_pubsub.schema import SchemaHandler 75 from sat_pubsub.schema import SchemaHandler
74 from sat_pubsub.privilege import PrivilegesHandler 76 from sat_pubsub.privilege import PrivilegesHandler
75 from sat_pubsub.delegation import DelegationsHandler 77 from sat_pubsub.delegation import DelegationsHandler
76 from os.path import expanduser, realpath 78 from os.path import expanduser, realpath
77 import ConfigParser 79 import ConfigParser
80
81
82 def coerceListType(value):
83 return csv.reader(
84 [value], delimiter=",", quotechar='"', skipinitialspace=True
85 ).next()
86
87
88 def coerceJidListType(value):
89 values = [JID(v) for v in coerceListType(value)]
90 if any((j.resource for j in values)):
91 raise ValueError(u"you must use bare jids")
92 return values
93
78 94
79 95
80 OPT_PARAMETERS_BOTH = [ 96 OPT_PARAMETERS_BOTH = [
81 ['jid', None, None, 'JID this component will be available at'], 97 ['jid', None, None, 'JID this component will be available at'],
82 ['xmpp_pwd', None, None, 'XMPP server component password'], 98 ['xmpp_pwd', None, None, 'XMPP server component password'],
88 ['db_pass', None, None, 'Database password (pgsql backend)'], 104 ['db_pass', None, None, 'Database password (pgsql backend)'],
89 ['db_host', None, None, 'Database host (pgsql backend)'], 105 ['db_host', None, None, 'Database host (pgsql backend)'],
90 ['db_port', None, None, 'Database port (pgsql backend)'], 106 ['db_port', None, None, 'Database port (pgsql backend)'],
91 ] 107 ]
92 # here for future use 108 # here for future use
93 OPT_PARAMETERS_CFG = [] 109 OPT_PARAMETERS_CFG = [
110 ["admins_jids_list", None, [], "List of administrators' bare jids",
111 coerceJidListType]
112 ]
94 113
95 CONFIG_FILENAME = u'sat' 114 CONFIG_FILENAME = u'sat'
96 # List of the configuration filenames sorted by ascending priority 115 # List of the configuration filenames sorted by ascending priority
97 CONFIG_FILES = [realpath(expanduser(path) + CONFIG_FILENAME + '.conf') for path in ( 116 CONFIG_FILES = [realpath(expanduser(path) + CONFIG_FILENAME + '.conf') for path in (
98 '/etc/', '/etc/{}/'.format(CONFIG_FILENAME), 117 '/etc/', '/etc/{}/'.format(CONFIG_FILENAME),
132 value = value.encode('utf-8') 151 value = value.encode('utf-8')
133 try: 152 try:
134 param[2] = param[4](value) 153 param[2] = param[4](value)
135 except IndexError: # the coerce method is optional 154 except IndexError: # the coerce method is optional
136 param[2] = value 155 param[2] = value
156 except Exception as e:
157 log.err(u'Invalid value for setting "{name}": {msg}'.format(
158 name=name, msg=e))
159 sys.exit(1)
137 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): 160 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
138 pass 161 pass
139 usage.Options.__init__(self) 162 usage.Options.__init__(self)
140 for opt_data in OPT_PARAMETERS_CFG: 163 for opt_data in OPT_PARAMETERS_CFG:
141 self[opt_data[0]] = opt_data[2] 164 self[opt_data[0]] = opt_data[2]
188 st = Storage(dbpool) 211 st = Storage(dbpool)
189 elif config['backend'] == 'memory': 212 elif config['backend'] == 'memory':
190 from sat_pubsub.memory_storage import Storage 213 from sat_pubsub.memory_storage import Storage
191 st = Storage() 214 st = Storage()
192 215
193 bs = BackendService(st) 216 bs = BackendService(st, config)
194 bs.setName('backend') 217 bs.setName('backend')
195 bs.setServiceParent(s) 218 bs.setServiceParent(s)
196 219
197 # Set up XMPP server-side component with publish-subscribe capabilities 220 # Set up XMPP server-side component with publish-subscribe capabilities
198 221