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

Fix #10: Remove boto3 stubs #13

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
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
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
Loading