Mercurial > libervia-pubsub
comparison idavoll/tap_http.py @ 177:faf1c9bc2612
Add HTTP gateway in a separate plugin.
Author: ralphm
Fixes #8.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Thu, 10 Apr 2008 11:18:29 +0000 |
parents | |
children | c21b986cff30 |
comparison
equal
deleted
inserted
replaced
176:17fc5dd77158 | 177:faf1c9bc2612 |
---|---|
1 # Copyright (c) 2003-2008 Ralph Meijer | |
2 # See LICENSE for details. | |
3 | |
4 from twisted.application import internet, strports | |
5 from twisted.conch import manhole, manhole_ssh | |
6 from twisted.cred import portal, checkers | |
7 from twisted.web2 import channel, resource, server | |
8 | |
9 from idavoll import gateway, tap | |
10 from idavoll.gateway import RemoteSubscriptionService | |
11 | |
12 class Options(tap.Options): | |
13 optParameters = [ | |
14 ('webport', None, '8086', 'Web port'), | |
15 ] | |
16 | |
17 | |
18 def getManholeFactory(namespace, **passwords): | |
19 def getManHole(_): | |
20 return manhole.Manhole(namespace) | |
21 | |
22 realm = manhole_ssh.TerminalRealm() | |
23 realm.chainedProtocolFactory.protocolFactory = getManHole | |
24 p = portal.Portal(realm) | |
25 p.registerChecker( | |
26 checkers.InMemoryUsernamePasswordDatabaseDontUse(**passwords)) | |
27 f = manhole_ssh.ConchFactory(p) | |
28 return f | |
29 | |
30 | |
31 def makeService(config): | |
32 s = tap.makeService(config) | |
33 | |
34 bs = s.getServiceNamed('backend') | |
35 cs = s.getServiceNamed('component') | |
36 | |
37 # Set up XMPP service for subscribing to remote nodes | |
38 | |
39 ss = RemoteSubscriptionService(config['jid']) | |
40 ss.setHandlerParent(cs) | |
41 ss.startService() | |
42 | |
43 # Set up web service that exposes the backend using REST | |
44 | |
45 root = resource.Resource() | |
46 root.child_create = gateway.CreateResource(bs, config['jid'], | |
47 config['jid']) | |
48 root.child_delete = gateway.DeleteResource(bs, config['jid'], | |
49 config['jid']) | |
50 root.child_publish = gateway.PublishResource(bs, config['jid'], | |
51 config['jid']) | |
52 root.child_subscribe = gateway.SubscribeResource(ss) | |
53 root.child_unsubscribe = gateway.UnsubscribeResource(ss) | |
54 root.child_list = gateway.ListResource(ss) | |
55 | |
56 site = server.Site(root) | |
57 w = internet.TCPServer(int(config['webport']), channel.HTTPFactory(site)) | |
58 w.setServiceParent(s) | |
59 | |
60 # Set up a manhole | |
61 | |
62 namespace = {'service': s, | |
63 'component': cs, | |
64 'backend': bs} | |
65 f = getManholeFactory(namespace, admin='admin') | |
66 manholeService = strports.service('2222', f) | |
67 manholeService.setServiceParent(s) | |
68 | |
69 return s | |
70 |