This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #824 from mozilla-services/fix/823
fix: impl. a haproxy endpoint that actually wraps SSL
- Loading branch information
Showing
4 changed files
with
178 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from twisted.internet import defer | ||
from twisted.internet.interfaces import IStreamServerEndpoint | ||
from twisted.protocols.haproxy._wrapper import HAProxyWrappingFactory | ||
from twisted.protocols.tls import TLSMemoryBIOFactory | ||
from zope.interface import implementer | ||
|
||
|
||
@implementer(IStreamServerEndpoint) | ||
class HAProxyServerEndpoint(object): | ||
"""A HAProxy endpoint, optionally handling TLS""" | ||
|
||
wrapper_factory = HAProxyWrappingFactory | ||
|
||
def __init__(self, reactor, port, ssl_cf=None, **kwargs): | ||
self._reactor = reactor | ||
self._port = port | ||
self._ssl_cf = ssl_cf | ||
self._kwargs = kwargs | ||
|
||
def listen(self, factory): | ||
"""Implement IStreamServerEndpoint.listen to listen on TCP. | ||
Optionally configuring TLS behind the HAProxy protocol. | ||
""" | ||
if self._ssl_cf: | ||
factory = TLSMemoryBIOFactory(self._ssl_cf, False, factory) | ||
proxyf = self.wrapper_factory(factory) | ||
return defer.execute(self._listen, self._port, proxyf, **self._kwargs) | ||
|
||
def _listen(self, *args, **kwargs): | ||
port = self._reactor.listenTCP(*args, **kwargs) | ||
if self._ssl_cf: | ||
port._type = 'TLS' | ||
return port |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters