Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(parameters): add overload signatures for get_parameter and get_parameters #3534

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
108 changes: 106 additions & 2 deletions aws_lambda_powertools/utilities/parameters/ssm.py
Expand Up @@ -545,9 +545,57 @@ def _raise_if_errors_key_is_present(parameters: Dict, reserved_parameter: str, r
)


@overload
def get_parameter(
name: str,
transform: None = None,
decrypt: Optional[bool] = None,
force_fetch: bool = False,
max_age: Optional[int] = None,
**sdk_options,
) -> str:
...


@overload
def get_parameter(
name: str,
transform: Literal["json"],
decrypt: Optional[bool] = None,
force_fetch: bool = False,
max_age: Optional[int] = None,
**sdk_options,
) -> dict:
...


@overload
def get_parameter(
name: str,
transform: Literal["binary"],
decrypt: Optional[bool] = None,
force_fetch: bool = False,
max_age: Optional[int] = None,
**sdk_options,
) -> Union[str, dict, bytes]:
...


@overload
def get_parameter(
name: str,
transform: Optional[str] = None,
transform: Literal["auto"],
decrypt: Optional[bool] = None,
force_fetch: bool = False,
max_age: Optional[int] = None,
**sdk_options,
) -> bytes:
...


def get_parameter(
name: str,
transform: Optional[Literal["json", "binary", "auto"]] = None,
decrypt: Optional[bool] = None,
force_fetch: bool = False,
max_age: Optional[int] = None,
Expand Down Expand Up @@ -625,9 +673,65 @@ def get_parameter(
)


@overload
def get_parameters(
path: str,
transform: None = None,
recursive: bool = True,
decrypt: Optional[bool] = None,
force_fetch: bool = False,
max_age: Optional[int] = None,
raise_on_transform_error: bool = False,
**sdk_options,
) -> Dict[str, str]:
...


@overload
def get_parameters(
path: str,
transform: Literal["json"],
recursive: bool = True,
decrypt: Optional[bool] = None,
force_fetch: bool = False,
max_age: Optional[int] = None,
raise_on_transform_error: bool = False,
**sdk_options,
) -> Dict[str, dict]:
...


@overload
def get_parameters(
path: str,
transform: Literal["binary"],
recursive: bool = True,
decrypt: Optional[bool] = None,
force_fetch: bool = False,
max_age: Optional[int] = None,
raise_on_transform_error: bool = False,
**sdk_options,
) -> Dict[str, bytes]:
...


@overload
def get_parameters(
path: str,
transform: Literal["auto"],
recursive: bool = True,
decrypt: Optional[bool] = None,
force_fetch: bool = False,
max_age: Optional[int] = None,
raise_on_transform_error: bool = False,
**sdk_options,
) -> Union[Dict[str, bytes], Dict[str, dict], Dict[str, str]]:
...


def get_parameters(
path: str,
transform: Optional[str] = None,
transform: Optional[Literal["json", "binary", "auto"]] = None,
recursive: bool = True,
decrypt: Optional[bool] = None,
force_fetch: bool = False,
Expand Down
Expand Up @@ -7,7 +7,7 @@
def lambda_handler(event: dict, context: LambdaContext) -> dict:
try:
# Retrieve a single parameter
endpoint_comments: str = parameters.get_parameter("/lambda-powertools/endpoint_comments") # type: ignore[assignment] # noqa: E501
endpoint_comments = parameters.get_parameter("/lambda-powertools/endpoint_comments")

# the value of this parameter is https://jsonplaceholder.typicode.com/comments/
comments: requests.Response = requests.get(endpoint_comments)
Expand Down