MCPcopy Create free account
hub / github.com/FareedKhan-dev/ai-long-task / _resolve_env_var

Function _resolve_env_var

config.py:25–51  ·  view source on GitHub ↗

Resolve ${VAR} environment variable reference in a string value. The pattern must match the entire string (e.g., "${OPENAI_API_KEY}"), not be embedded within other text. Args: value: The string value that may contain ${VAR} syntax. Returns: The resolved environ

(value: Optional[str])

Source from the content-addressed store, hash-verified

23
24
25def _resolve_env_var(value: Optional[str]) -> Optional[str]:
26 """
27 Resolve ${VAR} environment variable reference in a string value.
28 The pattern must match the entire string (e.g., "${OPENAI_API_KEY}"),
29 not be embedded within other text.
30
31 Args:
32 value: The string value that may contain ${VAR} syntax.
33
34 Returns:
35 The resolved environment variable value, or the original value if it doesn't match the pattern.
36
37 Raises:
38 ValueError: If the environment variable is referenced but not set.
39 """
40 if value is None:
41 return None
42
43 match = _ENV_VAR_PATTERN.match(value)
44 if not match:
45 return value
46
47 var_name = match.group(1)
48 env_value = os.environ.get(var_name)
49 if env_value is None:
50 raise ValueError(f"Environment variable {var_name} is not set")
51 return env_value
52
53
54@dataclass

Callers 1

__post_init__Method · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected