10918.2.3
by Steve Kowalik
Merge in the code for poppy-sftp |
1 |
# Copyright 2010 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
# This is a Twisted application config file. To run, use:
|
|
5 |
# twistd -noy sftp.tac
|
|
6 |
# or similar. Refer to the twistd(1) man page for details.
|
|
7 |
||
12392.7.27
by Julian Edwards
make logging work, and fix the sleep in the tests to look for a special log message instead |
8 |
import logging |
9 |
||
12392.7.21
by Julian Edwards
move code out of the tac file and into twistedftp.py |
10 |
from twisted.application import service |
11057.4.3
by Jonathan Lange
Use the DoNothing adapter. |
11 |
from twisted.conch.interfaces import ISession |
10918.2.3
by Steve Kowalik
Merge in the code for poppy-sftp |
12 |
from twisted.conch.ssh import filetransfer |
13 |
from twisted.cred.portal import IRealm, Portal |
|
12221.16.19
by Andrew Bennetts
Update poppy-sftp.tac for change to SSHService constructor. |
14 |
from twisted.protocols.policies import TimeoutFactory |
12392.7.13
by Julian Edwards
Move the new ftp code to its own file |
15 |
from twisted.python import components |
10918.2.3
by Steve Kowalik
Merge in the code for poppy-sftp |
16 |
from twisted.web.xmlrpc import Proxy |
17 |
||
18 |
from zope.interface import implements |
|
19 |
||
20 |
from canonical.config import config |
|
11765.1.1
by Robert Collins
Split out the launchpad-buildd needed component from tachandler.py. |
21 |
from canonical.launchpad.daemons import readyservice |
12392.8.1
by Julian Edwards
first stab at rejecting unsigned changes files - requires a patch to Twisted to return the error code properly |
22 |
from canonical.launchpad.scripts import execute_zcml_for_scripts |
10918.2.3
by Steve Kowalik
Merge in the code for poppy-sftp |
23 |
|
12392.7.21
by Julian Edwards
move code out of the tac file and into twistedftp.py |
24 |
from lp.poppy import get_poppy_root |
12919.6.13
by Ian Booth
Move job instantiation to separate class |
25 |
from lp.poppy.twistedconfigreset import GPGHandlerConfigResetJob |
12392.7.13
by Julian Edwards
Move the new ftp code to its own file |
26 |
from lp.poppy.twistedftp import ( |
12392.7.21
by Julian Edwards
move code out of the tac file and into twistedftp.py |
27 |
FTPServiceFactory, |
12392.7.13
by Julian Edwards
Move the new ftp code to its own file |
28 |
)
|
10918.2.3
by Steve Kowalik
Merge in the code for poppy-sftp |
29 |
from lp.poppy.twistedsftp import SFTPServer |
30 |
from lp.services.sshserver.auth import ( |
|
31 |
LaunchpadAvatar, PublicKeyFromLaunchpadChecker) |
|
32 |
from lp.services.sshserver.service import SSHService |
|
11057.4.3
by Jonathan Lange
Use the DoNothing adapter. |
33 |
from lp.services.sshserver.session import DoNothingSession |
10918.2.3
by Steve Kowalik
Merge in the code for poppy-sftp |
34 |
|
35 |
||
36 |
def make_portal(): |
|
37 |
"""Create and return a `Portal` for the SSH service.
|
|
38 |
||
39 |
This portal accepts SSH credentials and returns our customized SSH
|
|
40 |
avatars (see `LaunchpadAvatar`).
|
|
41 |
"""
|
|
42 |
authentication_proxy = Proxy( |
|
43 |
config.poppy.authentication_endpoint) |
|
44 |
portal = Portal(Realm(authentication_proxy)) |
|
45 |
portal.registerChecker( |
|
46 |
PublicKeyFromLaunchpadChecker(authentication_proxy)) |
|
47 |
return portal |
|
48 |
||
49 |
||
50 |
class Realm: |
|
51 |
implements(IRealm) |
|
52 |
||
53 |
def __init__(self, authentication_proxy): |
|
54 |
self.authentication_proxy = authentication_proxy |
|
55 |
||
56 |
def requestAvatar(self, avatar_id, mind, *interfaces): |
|
57 |
# Fetch the user's details from the authserver
|
|
58 |
deferred = mind.lookupUserDetails( |
|
59 |
self.authentication_proxy, avatar_id) |
|
60 |
||
61 |
# Once all those details are retrieved, we can construct the avatar.
|
|
62 |
def got_user_dict(user_dict): |
|
63 |
avatar = LaunchpadAvatar(user_dict) |
|
64 |
return interfaces[0], avatar, avatar.logout |
|
65 |
||
66 |
return deferred.addCallback(got_user_dict) |
|
67 |
||
68 |
||
69 |
def poppy_sftp_adapter(avatar): |
|
70 |
return SFTPServer(avatar, get_poppy_root()) |
|
71 |
||
72 |
||
12392.7.27
by Julian Edwards
make logging work, and fix the sleep in the tests to look for a special log message instead |
73 |
# Connect Python logging to Twisted's logging.
|
74 |
from lp.services.twistedsupport.loggingsupport import set_up_tacfile_logging |
|
75 |
set_up_tacfile_logging("poppy-sftp", logging.INFO) |
|
76 |
||
77 |
||
10918.2.3
by Steve Kowalik
Merge in the code for poppy-sftp |
78 |
components.registerAdapter( |
79 |
poppy_sftp_adapter, LaunchpadAvatar, filetransfer.ISFTPServer) |
|
80 |
||
11057.4.3
by Jonathan Lange
Use the DoNothing adapter. |
81 |
components.registerAdapter(DoNothingSession, LaunchpadAvatar, ISession) |
82 |
||
10918.2.3
by Steve Kowalik
Merge in the code for poppy-sftp |
83 |
|
12392.7.17
by Julian Edwards
get the port from the config |
84 |
# ftpport defaults to 2121 in schema-lazr.conf
|
12392.7.22
by Julian Edwards
ftp_port not ftpport |
85 |
ftpservice = FTPServiceFactory.makeFTPService(port=config.poppy.ftp_port) |
12392.7.1
by Julian Edwards
first crappy stab at ftp service inside poppy |
86 |
|
12392.7.16
by Julian Edwards
use the config's timeout |
87 |
# Construct an Application that has the Poppy SSH server,
|
88 |
# and the Poppy FTP server.
|
|
10918.2.3
by Steve Kowalik
Merge in the code for poppy-sftp |
89 |
application = service.Application('poppy-sftp') |
12221.16.19
by Andrew Bennetts
Update poppy-sftp.tac for change to SSHService constructor. |
90 |
|
12392.7.1
by Julian Edwards
first crappy stab at ftp service inside poppy |
91 |
ftpservice.setServiceParent(application) |
92 |
||
12221.16.19
by Andrew Bennetts
Update poppy-sftp.tac for change to SSHService constructor. |
93 |
def timeout_decorator(factory): |
94 |
"""Add idle timeouts to a factory."""
|
|
95 |
return TimeoutFactory(factory, timeoutPeriod=config.poppy.idle_timeout) |
|
96 |
||
10918.2.3
by Steve Kowalik
Merge in the code for poppy-sftp |
97 |
svc = SSHService( |
98 |
portal=make_portal(), |
|
99 |
private_key_path=config.poppy.host_key_private, |
|
100 |
public_key_path=config.poppy.host_key_public, |
|
101 |
oops_configuration='poppy', |
|
102 |
main_log='poppy', |
|
103 |
access_log='poppy.access', |
|
104 |
access_log_path=config.poppy.access_log, |
|
105 |
strport=config.poppy.port, |
|
12221.16.19
by Andrew Bennetts
Update poppy-sftp.tac for change to SSHService constructor. |
106 |
factory_decorator=timeout_decorator, |
10918.2.3
by Steve Kowalik
Merge in the code for poppy-sftp |
107 |
banner=config.poppy.banner) |
108 |
svc.setServiceParent(application) |
|
109 |
||
12392.8.1
by Julian Edwards
first stab at rejecting unsigned changes files - requires a patch to Twisted to return the error code properly |
110 |
# We need Zope for looking up the GPG utilities.
|
111 |
execute_zcml_for_scripts() |
|
112 |
||
12919.6.12
by Ian Booth
Move gpghandler job to poppy-sftp.tac |
113 |
# Set up the GPGHandler job
|
12919.6.14
by Ian Booth
Set up service properly using twisted |
114 |
GPGHandlerConfigResetJob().setServiceParent(application) |
12919.6.12
by Ian Booth
Move gpghandler job to poppy-sftp.tac |
115 |
|
10918.2.3
by Steve Kowalik
Merge in the code for poppy-sftp |
116 |
# Service that announces when the daemon is ready
|
11765.1.1
by Robert Collins
Split out the launchpad-buildd needed component from tachandler.py. |
117 |
readyservice.ReadyService().setServiceParent(application) |