Skip to content

Commit db389e6

Browse files
committed
fixed code smell
1 parent 4f780a7 commit db389e6

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

client_encryption/field_level_encryption.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ def encrypt_payload(payload, config, _params=None):
1212
"""Encrypt some fields of a JSON payload using the given configuration."""
1313

1414
try:
15-
if type(payload) is dict:
16-
json_payload = copy.deepcopy(payload)
17-
else:
18-
json_payload = json.loads(payload)
15+
json_payload = copy.deepcopy(payload) if type(payload) is dict else json.loads(payload)
1916

2017
for elem, target in config.paths["$"].to_encrypt.items():
2118
if not _params:
@@ -50,13 +47,7 @@ def decrypt_payload(payload, config, _params=None):
5047
"""Decrypt some fields of a JSON payload using the given configuration."""
5148

5249
try:
53-
if type(payload) is dict:
54-
json_payload = payload
55-
else:
56-
try:
57-
json_payload = json.loads(payload)
58-
except json.JSONDecodeError: # not a json response - return it as is
59-
return payload
50+
json_payload = payload if type(payload) is dict else json.loads(payload)
6051

6152
for elem, target in config.paths["$"].to_decrypt.items():
6253
try:
@@ -92,6 +83,8 @@ def decrypt_payload(payload, config, _params=None):
9283

9384
return json_payload
9485

86+
except json.JSONDecodeError: # not a json response - return it as is
87+
return payload
9588
except (IOError, ValueError, TypeError) as e:
9689
raise EncryptionError("Payload decryption failed!", e)
9790

0 commit comments

Comments
 (0)