1
# -*- test-case-name: twisted.words.test.test_tap -*-
2
# Copyright (c) 2001-2005 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')]
26
for plg in plugin.getPlugins(iwords.IProtocolPlugin):
27
assert plg.name not in interfacePlugins
28
interfacePlugins[plg.name] = plg
29
optParameters.append((
32
'strports description of the port to bind for the ' + plg.name + ' server'))
35
def __init__(self, *a, **kw):
36
usage.Options.__init__(self, *a, **kw)
39
def opt_group(self, name):
40
"""Specify a group which should exist
42
self['groups'].append(name.decode(sys.stdin.encoding))
44
def opt_passwd(self, filename):
46
Name of a passwd-style file. (This is for
47
backwards-compatibility only; you should use the --auth
50
self.addChecker(checkers.FilePasswordDB(filename))
52
def makeService(config):
53
credCheckers = config.get('credCheckers', [])
54
wordsRealm = service.InMemoryWordsRealm(config['hostname'])
55
wordsPortal = portal.Portal(wordsRealm, credCheckers)
59
# XXX Attribute lookup on config is kind of bad - hrm.
60
for plgName in config.interfacePlugins:
61
port = config.get(plgName + '-port')
63
factory = config.interfacePlugins[plgName].getFactory(wordsRealm, wordsPortal)
64
svc = strports.service(port, factory)
65
svc.setServiceParent(msvc)
67
# This is bogus. createGroup is async. makeService must be
68
# allowed to return a Deferred or some crap.
69
for g in config['groups']:
70
wordsRealm.createGroup(g)