Skip to content

refactor(parameters): improve typing for get_secret method #3910

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions aws_lambda_powertools/utilities/parameters/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"""

import os
from typing import TYPE_CHECKING, Any, Dict, Optional, Union
from typing import TYPE_CHECKING, Any, Dict, Literal, Optional, Union, overload

import boto3
from botocore.config import Config

from aws_lambda_powertools.utilities.parameters.types import TransformOptions

if TYPE_CHECKING:
from mypy_boto3_secretsmanager import SecretsManagerClient

Expand Down Expand Up @@ -116,9 +118,49 @@ def _get_multiple(self, path: str, **sdk_options) -> Dict[str, str]:
raise NotImplementedError()


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


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


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


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


def get_secret(
name: str,
transform: Optional[str] = None,
transform: TransformOptions = None,
force_fetch: bool = False,
max_age: Optional[int] = None,
**sdk_options,
Expand Down