Skip to content

Commit

Permalink
refactor(parameters): improve typing for get_secret method (#3910)
Browse files Browse the repository at this point in the history
fix: add overloads for get_secret function

Co-authored-by: Leandro Damascena <[email protected]>
  • Loading branch information
TonySherman and leandrodamascena authored Mar 8, 2024
1 parent c8c01ec commit 1b4a57e
Showing 1 changed file with 44 additions and 2 deletions.
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

0 comments on commit 1b4a57e

Please sign in to comment.