1 # -*- test-case-name: twisted.words.test.test_tap -*-
2 # Copyright (c) Twisted Matrix Laboratories.
3 # See LICENSE for details.
5 Shiny new words service maker
10 from twisted.application import strports
11 from twisted.application.service import MultiService
12 from twisted.python import usage
13 from twisted import plugin
15 from twisted.words import iwords, service
16 from twisted.cred import checkers, credentials, portal, strcred
18 class Options(usage.Options, strcred.AuthOptionMixin):
19 supportedInterfaces = [credentials.IUsernamePassword]
21 ('hostname', None, socket.gethostname(),
22 'Name of this server; purely an informative')]
24 compData = usage.Completions(multiUse=["group"])
28 for plg in plugin.getPlugins(iwords.IProtocolPlugin):
29 assert plg.name not in interfacePlugins
30 interfacePlugins[plg.name] = plg
31 optParameters.append((
34 'strports description of the port to bind for the ' + plg.name + ' server'))
37 def __init__(self, *a, **kw):
38 usage.Options.__init__(self, *a, **kw)
41 def opt_group(self, name):
42 """Specify a group which should exist
44 self['groups'].append(name.decode(sys.stdin.encoding))
46 def opt_passwd(self, filename):
48 Name of a passwd-style file. (This is for
49 backwards-compatibility only; you should use the --auth
52 self.addChecker(checkers.FilePasswordDB(filename))
54 def makeService(config):
55 credCheckers = config.get('credCheckers', [])
56 wordsRealm = service.InMemoryWordsRealm(config['hostname'])
57 wordsPortal = portal.Portal(wordsRealm, credCheckers)
61 # XXX Attribute lookup on config is kind of bad - hrm.
62 for plgName in config.interfacePlugins:
63 port = config.get(plgName + '-port')
65 factory = config.interfacePlugins[plgName].getFactory(wordsRealm, wordsPortal)
66 svc = strports.service(port, factory)
67 svc.setServiceParent(msvc)
69 # This is bogus. createGroup is async. makeService must be
70 # allowed to return a Deferred or some crap.
71 for g in config['groups']:
72 wordsRealm.createGroup(g)