@@ -18,25 +18,24 @@ def __init__(self, encryption_conf_file):
1818 self ._encryption_conf = FieldLevelEncryptionConfig (json_file .read ())
1919
2020 def field_encryption (self , func ):
21- """Decorator for API request . func is APIClient.request """
21+ """Decorator for API call_api . func is APIClient.call_api """
2222
2323 @wraps (func )
24- def request_function (* args , ** kwargs ):
25- """Wrap request and add field encryption layer to it."""
24+ def call_api_function (* args , ** kwargs ):
25+ """Wrap call_api and add field encryption layer to it."""
2626
2727 in_body = kwargs .get ("body" , None )
2828 kwargs ["body" ] = self ._encrypt_payload (kwargs .get ("headers" , None ), in_body ) if in_body else in_body
29+ kwargs ["_preload_content" ] = False
2930
3031 response = func (* args , ** kwargs )
3132
32- if type (response .data ) is not str :
33- response_body = self ._decrypt_payload (response .getheaders (), response .json ())
34- response ._content = json .dumps (response_body , indent = 4 ).encode ('utf-8' )
33+ response_body = self ._decrypt_payload (response .getheaders (), response .data )
3534
36- return response
35+ return response_body
3736
38- request_function .__fle__ = True
39- return request_function
37+ call_api_function .__fle__ = True
38+ return call_api_function
4039
4140 def _encrypt_payload (self , headers , body ):
4241 """Encryption enforcement based on configuration - encrypt and add session key params to header or body"""
@@ -86,10 +85,10 @@ def _decrypt_payload(self, headers, body):
8685
8786
8887def add_encryption_layer (api_client , encryption_conf_file ):
89- """Decorate APIClient.request with field level encryption"""
88+ """Decorate APIClient.call_api with field level encryption"""
9089
9190 api_encryption = ApiEncryption (encryption_conf_file )
92- api_client .request = api_encryption .field_encryption (api_client .request )
91+ api_client .call_api = api_encryption .field_encryption (api_client .call_api )
9392
9493 __check_oauth (api_client ) # warn the user if authentication layer is missing/not set
9594
0 commit comments