summaryrefslogtreecommitdiff
path: root/src/leap/mx/tcp_map.py
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2015-04-15 12:48:34 -0300
committerdrebs <drebs@leap.se>2015-04-16 11:53:13 -0300
commit527d7d4a67f859a3315812b100b2c58fd0eeded6 (patch)
treeb51959b18ec0053f9ed448cec9bd8c1bc98eb607 /src/leap/mx/tcp_map.py
parent14ef3dcce18240b756415fefa2a56936f96a12e9 (diff)
[bug] return uuid as result of alias resolver
This fixes a bug introduced on b0ef529cc882a96903597fb5279919969fa286c3, when the alias resolver was modified to return the user's address instead of the uuid. In order to fix this, I had to revert one of the changes made by the commit above, which is to don't make use of reduced view for the uuid query. The pgp public key query remains reduced, as implemented in the commit above. We also refactor the code a bit to allow for log messages specific to each of tcp map's sublasses. Related: #6858.
Diffstat (limited to 'src/leap/mx/tcp_map.py')
-rw-r--r--src/leap/mx/tcp_map.py30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/leap/mx/tcp_map.py b/src/leap/mx/tcp_map.py
index d8cd835..108c2aa 100644
--- a/src/leap/mx/tcp_map.py
+++ b/src/leap/mx/tcp_map.py
@@ -17,8 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from twisted.python import log
+from abc import ABCMeta
+from abc import abstractproperty
+
from twisted.internet.protocol import ServerFactory
+from twisted.python import log
# For info on codes, see: http://www.postfix.org/tcp_table.5.html
@@ -27,11 +30,14 @@ TCP_MAP_CODE_TEMPORARY_FAILURE = 400
TCP_MAP_CODE_PERMANENT_FAILURE = 500
-class LEAPPostfixTCPMapServerFactory(ServerFactory):
+class LEAPPostfixTCPMapServerFactory(ServerFactory, object):
"""
A factory for postfix tcp map servers.
"""
+ __metaclass__ = ABCMeta
+
+
def __init__(self, couchdb):
"""
Initialize the factory.
@@ -41,14 +47,22 @@ class LEAPPostfixTCPMapServerFactory(ServerFactory):
"""
self._cdb = couchdb
- def get(self, key):
+ @abstractproperty
+ def _query_message(self):
+ pass
+
+ def get(self, lookup_key):
"""
- Look up if address exists.
+ Look up user based on lookup_key.
+
+ :param lookup_key: The lookup key.
+ :type lookup_key: str
- :param key: The lookup key.
- :type key: str
+ :return: A deferred that will be fired with the user's address, uuid
+ and pgp key.
+ :rtype: Deferred
"""
- log.msg("Query key: %s" % (key,))
- d = self._cdb.queryByAddress(key)
+ log.msg("%s %s" % (self._query_message, lookup_key,))
+ d = self._cdb.getUuidAndPubkey(lookup_key)
d.addErrback(log.err)
return d