23
23
from .helpers import get_test_id , is_live , is_live_and_not_recording
24
24
from .proxy_testcase import start_record_or_playback , stop_record_or_playback , transform_request
25
25
from .proxy_startup import test_proxy
26
- from .sanitizers import add_general_string_sanitizer
26
+ from .sanitizers import add_batch_sanitizers , add_general_string_sanitizer , Sanitizer
27
27
28
28
if TYPE_CHECKING :
29
29
from typing import Any , Callable , Dict , Optional , Tuple
@@ -55,7 +55,7 @@ def sanitize(self, variable: str, value: str) -> str:
55
55
self ._fake_values [variable ] = value
56
56
real_value = os .getenv (variable )
57
57
if real_value :
58
- add_general_string_sanitizer (target = real_value , value = value )
58
+ add_general_string_sanitizer (target = real_value , value = value , function_scoped = True )
59
59
else :
60
60
_LOGGER .info (f"No value for { variable } was found, so a sanitizer could not be registered for the variable." )
61
61
@@ -70,8 +70,19 @@ def sanitize_batch(self, variables: "Dict[str, str]") -> "Dict[str, str]":
70
70
:returns: A dictionary mapping environment variables to their real values in live mode, or their sanitized
71
71
values in playback.
72
72
"""
73
- current_values = {variable : self .sanitize (variable , variables [variable ]) for variable in variables }
74
- return current_values
73
+ real_values = {}
74
+ sanitizers = {Sanitizer .GENERAL_STRING : []}
75
+
76
+ for variable in variables :
77
+ self ._fake_values [variable ] = variables [variable ]
78
+ real_value = os .getenv (variable )
79
+ real_values [variable ] = real_value
80
+ # If the variable has a value to be sanitized, add a general string sanitizer for it to our batch request
81
+ if real_value :
82
+ sanitizers [Sanitizer .GENERAL_STRING ].append ({"target" : real_value , "value" : variables [variable ]})
83
+
84
+ add_batch_sanitizers (sanitizers )
85
+ return real_values if is_live () else self ._fake_values
75
86
76
87
def get (self , variable : str ) -> str :
77
88
"""Returns the value of the specified environment variable in live mode, or the sanitized value in playback.
0 commit comments