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
This commit is contained in:
Tim Burke 2018-10-16 20:09:40 +00:00
parent 0d774861cb
commit 00f7732193
1 changed files with 5 additions and 16 deletions

View File

@ -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,