From 00f77321937f5f9db45a24eb9eeda76eb80c8063 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Tue, 16 Oct 2018 20:09:40 +0000 Subject: [PATCH] Simplify the decryption of container listings Following https://github.com/openstack/swift/commit/4806434 there is only one handler that might be used. Following https://github.com/openstack/swift/commit/2722e49 all EncryptionException errors should be caught and handled in decrypt_obj_dict. Change-Id: Ib4e9db400a58853daa903ae0a625dfde47747552 --- swift/common/middleware/crypto/decrypter.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/swift/common/middleware/crypto/decrypter.py b/swift/common/middleware/crypto/decrypter.py index a895db47e1..02e575361a 100644 --- a/swift/common/middleware/crypto/decrypter.py +++ b/swift/common/middleware/crypto/decrypter.py @@ -17,6 +17,7 @@ import base64 import json from swift import gettext_ as _ +from swift.common.header_key_dict import HeaderKeyDict from swift.common.http import is_success from swift.common.middleware.crypto.crypto_utils import CryptoWSGIContext, \ load_crypto_meta, extract_crypto_meta, Crypto @@ -353,22 +354,10 @@ class DecrypterContContext(BaseDecrypterContext): if is_success(self._get_status_int()): # only decrypt body of 2xx responses - handler = None - for header, value in self._response_headers: - if header.lower() == 'content-type' and \ - value.split(';', 1)[0] == 'application/json': - handler = self.process_json_resp - - if handler: - try: - app_resp = handler(req, app_resp) - except EncryptionException as err: - self.logger.error( - "Error decrypting container listing: %s", - err) - raise HTTPInternalServerError( - body='Error decrypting container listing', - content_type='text/plain') + headers = HeaderKeyDict(self._response_headers) + content_type = headers.get('content-type', '').split(';', 1)[0] + if content_type == 'application/json': + app_resp = self.process_json_resp(req, app_resp) start_response(self._response_status, self._response_headers,