Mercurial > libervia-pubsub
diff 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 |
line wrap: on
line diff
--- a/twisted/plugins/pubsub.py Fri Oct 15 09:32:04 2021 +0200 +++ b/twisted/plugins/pubsub.py Fri Oct 15 09:32:07 2021 +0200 @@ -64,8 +64,6 @@ from sat_pubsub import const - - def coerceListType(value): return next(csv.reader( [value], delimiter=",", quotechar='"', skipinitialspace=True @@ -79,10 +77,23 @@ return values +def coerceJidDomainType(value): + try: + jid_ = JID(value) + except Exception as e: + raise ValueError(f"JID set in configuration ({value!r}) is invalid: {e}") + if jid_.resource or jid_.user: + raise ValueError( + f"JID in configuration ({jid_!r}) must have no local part and no resource" + ) + return jid_ + OPT_PARAMETERS_BOTH = [ - ['jid', None, None, 'JID this component will be available at'], + ['jid', None, None, 'JID this component will be available at', coerceJidDomainType], ['xmpp_pwd', None, None, 'XMPP server component password'], + ['server_jid', None, None, 'jid of the server this component is plugged to', + coerceJidDomainType], ['rhost', None, '127.0.0.1', 'XMPP server host'], ['rport', None, '5347', 'XMPP server port'], ['backend', None, 'pgsql', 'Choice of storage backend'], @@ -148,7 +159,7 @@ ] def __init__(self): - """Read SàT Pubsub configuration file in order to overwrite the hard-coded default values. + """Read Libervia Pubsub configuration file in order to overwrite the hard-coded default values. Priority for the usage of the values is (from lowest to highest): - hard-coded default values @@ -200,8 +211,6 @@ if self['backend'] == 'memory': raise NotImplementedError('memory backend is not available at the moment') - self['jid'] = JID(self['jid']) if self['jid'] else None - @implementer(IServiceMaker, IPlugin) class SatPubsubMaker(object):