|
23 | 23 |
|
24 | 24 |
|
25 | 25 | @overload |
26 | | -def _try_powerfx_eval(value: None) -> None: ... |
| 26 | +def _try_powerfx_eval(value: None, log_value: bool = True) -> None: ... |
27 | 27 |
|
28 | 28 |
|
29 | 29 | @overload |
30 | | -def _try_powerfx_eval(value: str) -> str: ... |
| 30 | +def _try_powerfx_eval(value: str, log_value: bool = True) -> str: ... |
31 | 31 |
|
32 | 32 |
|
33 | | -def _try_powerfx_eval(value: str | None) -> str | None: |
34 | | - """Check if a value refers to a environment variable and parse it if so.""" |
| 33 | +def _try_powerfx_eval(value: str | None, log_value: bool = True) -> str | None: |
| 34 | + """Check if a value refers to a environment variable and parse it if so. |
| 35 | +
|
| 36 | + Args: |
| 37 | + value: The value to check. |
| 38 | + log_value: Whether to log the full value on error or just a snippet. |
| 39 | + """ |
35 | 40 | if value is None: |
36 | 41 | return value |
37 | 42 | if not value.startswith("="): |
38 | 43 | return value |
39 | 44 | if engine is None: |
40 | 45 | logger.warning( |
41 | | - f"PowerFx engine not available for evaluating value: {value}" |
42 | | - "Ensure you are on python 3.13 or less and have the powerfx package installed." |
| 46 | + "PowerFx engine not available for evaluating values starting with '='. " |
| 47 | + "Ensure you are on python 3.13 or less and have the powerfx package installed. " |
43 | 48 | "Otherwise replace all powerfx statements in your yaml with strings." |
44 | 49 | ) |
45 | 50 | return value |
46 | 51 | try: |
47 | 52 | return engine.eval(value[1:], symbols={"Env": dict(os.environ)}) |
48 | 53 | except Exception as exc: |
49 | | - logger.info("PowerFx evaluation failed for value '%s': %s", value, exc) |
| 54 | + if log_value: |
| 55 | + logger.debug("PowerFx evaluation failed for value '%s': %s", value, exc) |
| 56 | + else: |
| 57 | + logger.debug("PowerFx evaluation failed for value (first five characters shown) '%s': %s", value[:5], exc) |
50 | 58 | return value |
51 | 59 |
|
52 | 60 |
|
@@ -324,7 +332,7 @@ def __init__( |
324 | 332 | ) |
325 | 333 | self.endpoint = _try_powerfx_eval(endpoint) |
326 | 334 | # Support both 'apiKey' and 'key' fields, with 'key' taking precedence if both are provided |
327 | | - self.apiKey = _try_powerfx_eval(key if key else apiKey) |
| 335 | + self.apiKey = _try_powerfx_eval(key if key else apiKey, False) |
328 | 336 |
|
329 | 337 |
|
330 | 338 | class AnonymousConnection(Connection): |
|
0 commit comments