Ejemplo n.º 1
0
    def listen(self):
        assert self._port is None
        assert self.avatarClass is not None
        # FIXME: we should hand a username and password to log in with to
        # the job process instead of allowing anonymous
        checker = checkers.FlexibleCredentialsChecker()
        checker.allowPasswordless(True)
        p = portal.Portal(self, [checker])
        f = pb.PBServerFactory(p)
        try:
            os.unlink(self._socketPath)
        except OSError:
            pass

        # Rather than a listenUNIX(), we use listenWith so that we can specify
        # our particular Port, which creates Transports that we know how to
        # pass FDs over.
        self.debug("Listening for FD's on unix socket %s", self._socketPath)
        port = reactor.listenWith(fdserver.FDPort, self._socketPath, f)
        self._port = port
Ejemplo n.º 2
0
 def __init__(self):
     checker = checkers.FlexibleCredentialsChecker()
     checker.addUser("username", "password")
     portal.Portal.__init__(self, FakeTRealm(), (checker, ))
Ejemplo n.º 3
0
    def do_setup(self):
        # Create our combined PB-server/fd-passing channel
        self.have_properties()
        realm = PorterRealm(self)
        checker = checkers.FlexibleCredentialsChecker()
        checker.addUser(self._username, self._password)
        if not self._requirePassword:
            checker.allowPasswordless(True)

        p = portal.Portal(realm, [checker])
        serverfactory = pb.PBServerFactory(p)

        try:
            # Rather than a normal listenTCP() or listenUNIX(), we use
            # listenWith so that we can specify our particular Port, which
            # creates Transports that we know how to pass FDs over.
            try:
                os.unlink(self._socketPath)
            except OSError:
                pass

            self._socketlistener = reactor.listenWith(fdserver.FDPort,
                                                      self._socketPath,
                                                      serverfactory,
                                                      mode=self._socketMode)
            self.info("Now listening on socketPath %s", self._socketPath)
        except error.CannotListenError:
            self.warning("Failed to create socket %s" % self._socketPath)
            m = messages.Error(
                T_(N_("Network error: socket path %s is not available."),
                   self._socketPath))
            self.addMessage(m)
            self.setMood(moods.sad)
            return defer.fail(errors.ComponentSetupHandledError())

        # Create the class that deals with the specific protocol we're proxying
        # in this porter.
        try:
            proto = reflect.namedAny(self._porterProtocol)
            self.debug("Created proto %r" % proto)
        except (ImportError, AttributeError):
            self.warning("Failed to import protocol '%s', defaulting to HTTP" %
                         self._porterProtocol)
            proto = HTTPPorterProtocol

        # And of course we also want to listen for incoming requests in the
        # appropriate protocol (HTTP, RTSP, etc.)
        factory = PorterProtocolFactory(self, proto)
        try:
            reactor.listenWith(fdserver.PassableServerPort,
                               self._port,
                               factory,
                               interface=self._interface)
            self.info("Now listening on interface %r on port %d",
                      self._interface, self._port)
        except error.CannotListenError:
            self.warning("Failed to listen on interface %r on port %d",
                         self._interface, self._port)
            m = messages.Error(
                T_(N_("Network error: TCP port %d is not available."),
                   self._port))
            self.addMessage(m)
            self.setMood(moods.sad)
            return defer.fail(errors.ComponentSetupHandledError())
Ejemplo n.º 4
0
 def setUp(self):
     self.checker = checkers.FlexibleCredentialsChecker(user='******')
     self.checker.allowPasswordless(True)
Ejemplo n.º 5
0
 def setUp(self):
     self.checker = checkers.FlexibleCredentialsChecker(user='******')