Skip to content

Commit

Permalink
Merge pull request #13 from ceb10n/features/remove-boto3-stubs
Browse files Browse the repository at this point in the history
Remove boto3 stubs
  • Loading branch information
ceb10n authored Jul 22, 2024
2 parents e0c51e8 + 45392c5 commit 7eb620c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
35 changes: 11 additions & 24 deletions pydantic_settings_aws/aws.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import json
from typing import Any, AnyStr, Dict, Optional, Union

import boto3
from mypy_boto3_secretsmanager import SecretsManagerClient
from mypy_boto3_secretsmanager.type_defs import GetSecretValueResponseTypeDef
from mypy_boto3_ssm import SSMClient
import boto3 # type: ignore[import-untyped]
from pydantic import ValidationError
from pydantic_settings import BaseSettings

Expand Down Expand Up @@ -36,7 +33,7 @@ def get_ssm_content(

if not client:
logger.debug("Boto3 client not specified in metadata")
client = _get_ssm_boto3_client(settings) # type: ignore
client = _get_ssm_boto3_client(settings)

logger.debug(f"Getting parameter {ssm_name} value with boto3 client")
ssm_response: dict[str, Any] = client.get_parameter( # type: ignore
Expand All @@ -47,11 +44,11 @@ def get_ssm_content(


def get_secrets_content(settings: type[BaseSettings]) -> dict[str, Any]:
client: SecretsManagerClient = _get_secrets_boto3_client(settings)
client = _get_secrets_boto3_client(settings)
secrets_args: AwsSecretsArgs = _get_secrets_args(settings)

logger.debug("Getting secrets manager value with boto3 client")
secret_response: GetSecretValueResponseTypeDef = client.get_secret_value(
secret_response = client.get_secret_value(
**secrets_args.model_dump(by_alias=True, exclude_none=True)
)

Expand All @@ -72,13 +69,9 @@ def get_secrets_content(settings: type[BaseSettings]) -> dict[str, Any]:
raise json_err


def _get_secrets_boto3_client(
settings: type[BaseSettings],
) -> SecretsManagerClient:
def _get_secrets_boto3_client( settings: type[BaseSettings]): # type: ignore[no-untyped-def]
logger.debug("Getting secrets manager content.")
client: SecretsManagerClient | None = settings.model_config.get( # type: ignore
"secrets_client", None
)
client = settings.model_config.get("secrets_client", None)

if client:
return client
Expand All @@ -87,9 +80,7 @@ def _get_secrets_boto3_client(
return _create_secrets_client(settings)


def _create_secrets_client(
settings: type[BaseSettings],
) -> SecretsManagerClient:
def _create_secrets_client(settings: type[BaseSettings]): # type: ignore[no-untyped-def]
"""Create a boto3 client for secrets manager.
Neither `boto3` nor `pydantic` exceptions will be handled.
Expand Down Expand Up @@ -136,7 +127,7 @@ def _get_secrets_args(settings: type[BaseSettings]) -> AwsSecretsArgs:


def _get_secrets_content(
secret: GetSecretValueResponseTypeDef,
secret: Dict[str, Any],
) -> Optional[str]:
secrets_content: Optional[str] = None

Expand All @@ -161,11 +152,9 @@ def _get_secrets_content(
return secrets_content


def _get_ssm_boto3_client(settings: type[BaseSettings]) -> SSMClient:
def _get_ssm_boto3_client(settings: type[BaseSettings]): # type: ignore[no-untyped-def]
logger.debug("Getting secrets manager content.")
client: SSMClient | None = settings.model_config.get( # type: ignore
"ssm_client", None
)
client = settings.model_config.get("ssm_client", None)

if client:
return client
Expand All @@ -176,9 +165,7 @@ def _get_ssm_boto3_client(settings: type[BaseSettings]) -> SSMClient:
return _create_ssm_client(settings)


def _create_ssm_client(
settings: type[BaseSettings],
) -> SSMClient:
def _create_ssm_client(settings: type[BaseSettings]): # type: ignore[no-untyped-def]
"""Create a boto3 client for parameter store.
Neither `boto3` nor `pydantic` exceptions will be handled.
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ requires-python = '>=3.9'
dependencies = [
'pydantic>=2.0.1',
'pydantic-settings>=2.0.2',
'boto3>=1.27.0',
'boto3-stubs[secretsmanager]>=1.27.0',
'boto3-stubs[ssm]>=1.27.0'
'boto3>=1.27.0'
]
dynamic = ['version']

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
-e .

boto3>=1.34.142
boto3-stubs[secretsmanager]>=1.34.142
pydantic>=2.0.1
pydantic-settings>=2.0.2

0 comments on commit 7eb620c

Please sign in to comment.