Mercurial > libervia-pubsub
comparison twisted/plugins/pubsub.py @ 460:607616f9ef5b
backend: new `server_jid` option:
Server domain must be known to validate requests, this can be done explicitely by using the
`server_jid` option. If this option is not set, the server domain is found:
- by using the `from` name of the initial delegation advertising message
- or it fallbacks to using the part after initial `.` (`pubsub.example.org` would give
`example.org`)
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 15 Oct 2021 09:32:07 +0200 |
parents | bc2e04a4d3c1 |
children | b544109ab4c4 |
comparison
equal
deleted
inserted
replaced
459:cebcb7f56889 | 460:607616f9ef5b |
---|---|
62 from twisted.words.protocols.jabber.jid import JID | 62 from twisted.words.protocols.jabber.jid import JID |
63 import sat_pubsub | 63 import sat_pubsub |
64 from sat_pubsub import const | 64 from sat_pubsub import const |
65 | 65 |
66 | 66 |
67 | |
68 | |
69 def coerceListType(value): | 67 def coerceListType(value): |
70 return next(csv.reader( | 68 return next(csv.reader( |
71 [value], delimiter=",", quotechar='"', skipinitialspace=True | 69 [value], delimiter=",", quotechar='"', skipinitialspace=True |
72 )) | 70 )) |
73 | 71 |
77 if any((j.resource for j in values)): | 75 if any((j.resource for j in values)): |
78 raise ValueError("you must use bare jids") | 76 raise ValueError("you must use bare jids") |
79 return values | 77 return values |
80 | 78 |
81 | 79 |
80 def coerceJidDomainType(value): | |
81 try: | |
82 jid_ = JID(value) | |
83 except Exception as e: | |
84 raise ValueError(f"JID set in configuration ({value!r}) is invalid: {e}") | |
85 if jid_.resource or jid_.user: | |
86 raise ValueError( | |
87 f"JID in configuration ({jid_!r}) must have no local part and no resource" | |
88 ) | |
89 return jid_ | |
90 | |
82 | 91 |
83 OPT_PARAMETERS_BOTH = [ | 92 OPT_PARAMETERS_BOTH = [ |
84 ['jid', None, None, 'JID this component will be available at'], | 93 ['jid', None, None, 'JID this component will be available at', coerceJidDomainType], |
85 ['xmpp_pwd', None, None, 'XMPP server component password'], | 94 ['xmpp_pwd', None, None, 'XMPP server component password'], |
95 ['server_jid', None, None, 'jid of the server this component is plugged to', | |
96 coerceJidDomainType], | |
86 ['rhost', None, '127.0.0.1', 'XMPP server host'], | 97 ['rhost', None, '127.0.0.1', 'XMPP server host'], |
87 ['rport', None, '5347', 'XMPP server port'], | 98 ['rport', None, '5347', 'XMPP server port'], |
88 ['backend', None, 'pgsql', 'Choice of storage backend'], | 99 ['backend', None, 'pgsql', 'Choice of storage backend'], |
89 ['db_user', None, None, 'Database user (pgsql backend)'], | 100 ['db_user', None, None, 'Database user (pgsql backend)'], |
90 ['db_name', None, 'pubsub', 'Database name (pgsql backend)'], | 101 ['db_name', None, 'pubsub', 'Database name (pgsql backend)'], |
146 ('verbose', 'v', 'Show traffic'), | 157 ('verbose', 'v', 'Show traffic'), |
147 ('hide-nodes', None, 'Hide all nodes for disco') | 158 ('hide-nodes', None, 'Hide all nodes for disco') |
148 ] | 159 ] |
149 | 160 |
150 def __init__(self): | 161 def __init__(self): |
151 """Read SàT Pubsub configuration file in order to overwrite the hard-coded default values. | 162 """Read Libervia Pubsub configuration file in order to overwrite the hard-coded default values. |
152 | 163 |
153 Priority for the usage of the values is (from lowest to highest): | 164 Priority for the usage of the values is (from lowest to highest): |
154 - hard-coded default values | 165 - hard-coded default values |
155 - values from SàT configuration files | 166 - values from SàT configuration files |
156 - values passed on the command line | 167 - values passed on the command line |
197 def postOptions(self): | 208 def postOptions(self): |
198 if self['backend'] not in ['pgsql', 'memory']: | 209 if self['backend'] not in ['pgsql', 'memory']: |
199 raise usage.UsageError("Unknown backend!") | 210 raise usage.UsageError("Unknown backend!") |
200 if self['backend'] == 'memory': | 211 if self['backend'] == 'memory': |
201 raise NotImplementedError('memory backend is not available at the moment') | 212 raise NotImplementedError('memory backend is not available at the moment') |
202 | |
203 self['jid'] = JID(self['jid']) if self['jid'] else None | |
204 | 213 |
205 | 214 |
206 @implementer(IServiceMaker, IPlugin) | 215 @implementer(IServiceMaker, IPlugin) |
207 class SatPubsubMaker(object): | 216 class SatPubsubMaker(object): |
208 tapname = "libervia-pubsub" | 217 tapname = "libervia-pubsub" |