~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/poppy/twistedftp.py

  • Committer: Julian Edwards
  • Date: 2011-02-23 15:16:38 UTC
  • mfrom: (12392.7.32 twisted-ftp-poppy)
  • mto: This revision was merged to the branch mainline in revision 12470.
  • Revision ID: julian.edwards@canonical.com-20110223151638-8cw0twgnyx2a8c0y
merge parent branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
import os
14
14
import tempfile
15
15
 
 
16
from twisted.application import service, strports
16
17
from twisted.cred import checkers, credentials
17
 
from twisted.cred.portal import IRealm
 
18
from twisted.cred.portal import IRealm, Portal
18
19
from twisted.internet import defer
19
20
from twisted.protocols import ftp
20
21
from twisted.python import filepath
27
28
    IGPGHandler,
28
29
    )
29
30
 
 
31
from canonical.config import config
 
32
from lp.poppy import get_poppy_root
30
33
from lp.poppy.filesystem import UploadFileSystem
31
34
from lp.poppy.hooks import Hooks
32
35
from lp.registry.interfaces.gpg import IGPGKeySet
35
38
class PoppyAccessCheck:
36
39
    """An `ICredentialsChecker` for Poppy FTP sessions."""
37
40
    implements(checkers.ICredentialsChecker)
38
 
    credentialInterfaces = credentials.IUsernamePassword,
 
41
    credentialInterfaces = (
 
42
        credentials.IUsernamePassword, credentials.IAnonymous)
39
43
 
40
44
    def requestAvatarId(self, credentials):
41
45
        # Poppy allows any credentials.  People can use "anonymous" if
42
 
        # they want but anything goes.  Returning "poppy" here is
43
 
        # a totally arbitrary avatar.
44
 
        return "poppy"
 
46
        # they want but anything goes.  Thus, we don't actually *check* the
 
47
        # credentials, and we return the standard avatarId for 'anonymous'.
 
48
        return checkers.ANONYMOUS
45
49
 
46
50
 
47
51
class PoppyAnonymousShell(ftp.FTPShell):
175
179
        return None
176
180
 
177
181
 
 
182
class FTPServiceFactory(service.Service):
 
183
    """A factory that makes an `FTPService`"""
 
184
 
 
185
    def __init__(self, port):
 
186
        realm = FTPRealm(get_poppy_root())
 
187
        portal = Portal(realm)
 
188
        portal.registerChecker(PoppyAccessCheck())
 
189
        factory = ftp.FTPFactory(portal)
 
190
 
 
191
        factory.tld = get_poppy_root()
 
192
        factory.protocol = ftp.FTP
 
193
        factory.welcomeMessage = "Launchpad upload server"
 
194
        factory.timeOut = config.poppy.idle_timeout
 
195
 
 
196
        self.ftpfactory = factory
 
197
        self.portno = port
 
198
 
 
199
    @staticmethod
 
200
    def makeFTPService(port=2121):
 
201
        strport = "tcp:%s" % port
 
202
        factory = FTPServiceFactory(port)
 
203
        return strports.service(strport, factory.ftpfactory)