Module aws_lambda_powertools.shared.functions
Expand source code
from distutils.util import strtobool
from typing import Any, Optional, Union
def resolve_truthy_env_var_choice(env: Any, choice: bool = None) -> bool:
"""Pick explicit choice over truthy env value, if available, otherwise return truthy env value
NOTE: Environment variable should be resolved by the caller.
Parameters
----------
env : Any
environment variable actual value
choice : bool
explicit choice
Returns
-------
choice : str
resolved choice as either bool or environment value
"""
return choice if choice is not None else strtobool(env)
def resolve_env_var_choice(env: Any, choice: Optional[Any] = None) -> Union[bool, Any]:
"""Pick explicit choice over env, if available, otherwise return env value received
NOTE: Environment variable should be resolved by the caller.
Parameters
----------
env : Any
environment variable actual value
choice : bool
explicit choice
Returns
-------
choice : str
resolved choice as either bool or environment value
"""
return choice if choice is not None else env
Functions
-
Pick explicit choice over env, if available, otherwise return env value received
NOTE: Environment variable should be resolved by the caller.
Parameters
env
:Any
- environment variable actual value
choice
:bool
- explicit choice
Returns
choice
:str
- resolved choice as either bool or environment value
Expand source code
def resolve_env_var_choice(env: Any, choice: Optional[Any] = None) -> Union[bool, Any]: """Pick explicit choice over env, if available, otherwise return env value received NOTE: Environment variable should be resolved by the caller. Parameters ---------- env : Any environment variable actual value choice : bool explicit choice Returns ------- choice : str resolved choice as either bool or environment value """ return choice if choice is not None else env
-
Pick explicit choice over truthy env value, if available, otherwise return truthy env value
NOTE: Environment variable should be resolved by the caller.
Parameters
env
:Any
- environment variable actual value
choice
:bool
- explicit choice
Returns
choice
:str
- resolved choice as either bool or environment value
Expand source code
def resolve_truthy_env_var_choice(env: Any, choice: bool = None) -> bool: """Pick explicit choice over truthy env value, if available, otherwise return truthy env value NOTE: Environment variable should be resolved by the caller. Parameters ---------- env : Any environment variable actual value choice : bool explicit choice Returns ------- choice : str resolved choice as either bool or environment value """ return choice if choice is not None else strtobool(env)