From 814bb1f36db0ea331644eee32ae83fb4f2e99b7f Mon Sep 17 00:00:00 2001 From: kaiyou Date: Wed, 26 Sep 2018 20:56:26 +0200 Subject: [PATCH] Properly miss when the web api returns 404 --- core/base/libs/podop/podop/dovecot.py | 11 +++++------ core/base/libs/podop/podop/postfix.py | 2 ++ core/base/libs/podop/podop/table.py | 4 ++++ core/base/libs/podop/setup.py | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/core/base/libs/podop/podop/dovecot.py b/core/base/libs/podop/podop/dovecot.py index 96eea3b8..64074e38 100644 --- a/core/base/libs/podop/podop/dovecot.py +++ b/core/base/libs/podop/podop/dovecot.py @@ -81,11 +81,10 @@ class DictProtocol(asyncio.Protocol): logging.debug("Looking up {}".format(key)) # Priv and shared keys are handled slighlty differently key_type, key = key.decode("utf8").split("/", 1) - result = await self.dict.get( - key, ns=(self.user if key_type == "priv" else None) - ) - # Handle various response types - if result is not None: + try: + result = await self.dict.get( + key, ns=(self.user if key_type == "priv" else None) + ) if type(result) is str: response = result.encode("utf8") elif type(result) is bytes: @@ -93,7 +92,7 @@ class DictProtocol(asyncio.Protocol): else: response = json.dumps(result).encode("ascii") return self.reply(b"O", response) - else: + except KeyError: return self.reply(b"N") def process_begin(self, transaction_id): diff --git a/core/base/libs/podop/podop/postfix.py b/core/base/libs/podop/podop/postfix.py index b0395f35..84c7b08d 100644 --- a/core/base/libs/podop/podop/postfix.py +++ b/core/base/libs/podop/podop/postfix.py @@ -58,6 +58,7 @@ class NetstringProtocol(asyncio.Protocol): def send_string(self, string): """ Send a netstring """ + logging.debug("Replying {}".format(string)) self.transport.write(str(len(string)).encode('ascii')) self.transport.write(b':') self.transport.write(string) @@ -85,6 +86,7 @@ class SocketmapProtocol(NetstringProtocol): def string_received(self, string): # The postfix format contains a space for separating the map name and # the key + logging.debug("Received {}".format(string)) space = string.find(0x20) if space != -1: name = string[:space].decode('ascii') diff --git a/core/base/libs/podop/podop/table.py b/core/base/libs/podop/podop/table.py index ab53179e..3869cafc 100644 --- a/core/base/libs/podop/podop/table.py +++ b/core/base/libs/podop/podop/table.py @@ -28,6 +28,10 @@ class UrlTable(object): result = await request.json() logging.debug("Table get {} is {}".format(key, result)) return result + elif request.status == 404: + raise KeyError() + else: + raise Exception(request.status) async def set(self, key, value, ns=None): """ Set a value for the given key in the provided namespace diff --git a/core/base/libs/podop/setup.py b/core/base/libs/podop/setup.py index 82c998bc..d681ae53 100644 --- a/core/base/libs/podop/setup.py +++ b/core/base/libs/podop/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r") as fh: setup( name="podop", - version="0.2.2", + version="0.2.3", description="Postfix and Dovecot proxy", long_description=long_description, long_description_content_type="text/markdown",