11import logging
22from pathlib import Path
3- from typing import Any , Dict , Optional , Union
3+ from typing import TYPE_CHECKING , Any , Dict , Optional , Union
44
55import boto3
6- from pydantic import BaseSettings
6+
7+ from pydantic import BaseSettings , typing
8+
9+ if TYPE_CHECKING :
10+ from mypy_boto3_ssm .client import SSMClient
11+
712
813logger = logging .getLogger (__name__ )
914
1015
1116class AwsSsmSettingsSource :
1217 __slots__ = ("ssm_prefix" ,)
1318
14- def __init__ (self , ssm_prefix : Union [Path , str , None ]):
15- self .ssm_prefix : Union [Path , str , None ] = ssm_prefix
19+ def __init__ (self , ssm_prefix : Union [typing . StrPath , None ]):
20+ self .ssm_prefix : Union [typing . StrPath , None ] = ssm_prefix
1621
1722 @property
18- def client (self ):
23+ def client (self ) -> "SSMClient" :
1924 return boto3 .client ("ssm" )
2025
2126 def __call__ (self , settings : BaseSettings ) -> Dict [str , Any ]:
2227 """
2328 Returns lazy SSM values for all settings.
2429 """
2530 secrets : Dict [str , Optional [Any ]] = {}
26-
31+
2732 if self .ssm_prefix is None :
2833 return secrets
2934
@@ -34,10 +39,13 @@ def __call__(self, settings: BaseSettings) -> Dict[str, Any]:
3439
3540 logger .debug (f"Building SSM settings with prefix of { secrets_path = } " )
3641
37- params = self .client .get_parameters_by_path (Path = str (secrets_path ), WithDecryption = True )['Parameters' ]
42+ params = self .client .get_parameters_by_path (
43+ Path = str (secrets_path ), WithDecryption = True
44+ )["Parameters" ]
3845
3946 return {
40- str (Path (param ['Name' ]).relative_to (secrets_path )): param ['Value' ] for param in params
47+ str (Path (param ["Name" ]).relative_to (secrets_path )): param ["Value" ]
48+ for param in params
4149 }
4250
4351 def __repr__ (self ) -> str :
0 commit comments