Skip to content

Commit dfe42b1

Browse files
author
Michael Brewer
authored
feat(params): expose high level max_age, raise_on_transform_error (#567)
1 parent 0df5c57 commit dfe42b1

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

Diff for: aws_lambda_powertools/utilities/parameters/appconfig.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from ...shared import constants
1414
from ...shared.functions import resolve_env_var_choice
15-
from .base import DEFAULT_PROVIDERS, BaseProvider
15+
from .base import DEFAULT_MAX_AGE_SECS, DEFAULT_PROVIDERS, BaseProvider
1616

1717
CLIENT_ID = str(uuid4())
1818

@@ -110,6 +110,7 @@ def get_app_config(
110110
application: Optional[str] = None,
111111
transform: Optional[str] = None,
112112
force_fetch: bool = False,
113+
max_age: int = DEFAULT_MAX_AGE_SECS,
113114
**sdk_options
114115
) -> Union[str, list, dict, bytes]:
115116
"""
@@ -127,6 +128,8 @@ def get_app_config(
127128
Transforms the content from a JSON object ('json') or base64 binary string ('binary')
128129
force_fetch: bool, optional
129130
Force update even before a cached item has expired, defaults to False
131+
max_age: int
132+
Maximum age of the cached value
130133
sdk_options: dict, optional
131134
Dictionary of options that will be passed to the Parameter Store get_parameter API call
132135
@@ -165,4 +168,6 @@ def get_app_config(
165168

166169
sdk_options["ClientId"] = CLIENT_ID
167170

168-
return DEFAULT_PROVIDERS["appconfig"].get(name, transform=transform, force_fetch=force_fetch, **sdk_options)
171+
return DEFAULT_PROVIDERS["appconfig"].get(
172+
name, max_age=max_age, transform=transform, force_fetch=force_fetch, **sdk_options
173+
)

Diff for: aws_lambda_powertools/utilities/parameters/secrets.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import boto3
99
from botocore.config import Config
1010

11-
from .base import DEFAULT_PROVIDERS, BaseProvider
11+
from .base import DEFAULT_MAX_AGE_SECS, DEFAULT_PROVIDERS, BaseProvider
1212

1313

1414
class SecretsProvider(BaseProvider):
@@ -94,7 +94,11 @@ def _get_multiple(self, path: str, **sdk_options) -> Dict[str, str]:
9494

9595

9696
def get_secret(
97-
name: str, transform: Optional[str] = None, force_fetch: bool = False, **sdk_options
97+
name: str,
98+
transform: Optional[str] = None,
99+
force_fetch: bool = False,
100+
max_age: int = DEFAULT_MAX_AGE_SECS,
101+
**sdk_options
98102
) -> Union[str, dict, bytes]:
99103
"""
100104
Retrieve a parameter value from AWS Secrets Manager
@@ -107,6 +111,8 @@ def get_secret(
107111
Transforms the content from a JSON object ('json') or base64 binary string ('binary')
108112
force_fetch: bool, optional
109113
Force update even before a cached item has expired, defaults to False
114+
max_age: int
115+
Maximum age of the cached value
110116
sdk_options: dict, optional
111117
Dictionary of options that will be passed to the get_secret_value call
112118
@@ -143,4 +149,6 @@ def get_secret(
143149
if "secrets" not in DEFAULT_PROVIDERS:
144150
DEFAULT_PROVIDERS["secrets"] = SecretsProvider()
145151

146-
return DEFAULT_PROVIDERS["secrets"].get(name, transform=transform, force_fetch=force_fetch, **sdk_options)
152+
return DEFAULT_PROVIDERS["secrets"].get(
153+
name, max_age=max_age, transform=transform, force_fetch=force_fetch, **sdk_options
154+
)

Diff for: aws_lambda_powertools/utilities/parameters/ssm.py

+26-3
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,12 @@ def _get_multiple(self, path: str, decrypt: bool = False, recursive: bool = Fals
186186

187187

188188
def get_parameter(
189-
name: str, transform: Optional[str] = None, decrypt: bool = False, force_fetch: bool = False, **sdk_options
189+
name: str,
190+
transform: Optional[str] = None,
191+
decrypt: bool = False,
192+
force_fetch: bool = False,
193+
max_age: int = DEFAULT_MAX_AGE_SECS,
194+
**sdk_options
190195
) -> Union[str, list, dict, bytes]:
191196
"""
192197
Retrieve a parameter value from AWS Systems Manager (SSM) Parameter Store
@@ -201,6 +206,8 @@ def get_parameter(
201206
If the parameter values should be decrypted
202207
force_fetch: bool, optional
203208
Force update even before a cached item has expired, defaults to False
209+
max_age: int
210+
Maximum age of the cached value
204211
sdk_options: dict, optional
205212
Dictionary of options that will be passed to the Parameter Store get_parameter API call
206213
@@ -240,7 +247,9 @@ def get_parameter(
240247
# Add to `decrypt` sdk_options to we can have an explicit option for this
241248
sdk_options["decrypt"] = decrypt
242249

243-
return DEFAULT_PROVIDERS["ssm"].get(name, transform=transform, force_fetch=force_fetch, **sdk_options)
250+
return DEFAULT_PROVIDERS["ssm"].get(
251+
name, max_age=max_age, transform=transform, force_fetch=force_fetch, **sdk_options
252+
)
244253

245254

246255
def get_parameters(
@@ -249,6 +258,8 @@ def get_parameters(
249258
recursive: bool = True,
250259
decrypt: bool = False,
251260
force_fetch: bool = False,
261+
max_age: int = DEFAULT_MAX_AGE_SECS,
262+
raise_on_transform_error: bool = False,
252263
**sdk_options
253264
) -> Union[Dict[str, str], Dict[str, dict], Dict[str, bytes]]:
254265
"""
@@ -266,6 +277,11 @@ def get_parameters(
266277
If the parameter values should be decrypted
267278
force_fetch: bool, optional
268279
Force update even before a cached item has expired, defaults to False
280+
max_age: int
281+
Maximum age of the cached value
282+
raise_on_transform_error: bool, optional
283+
Raises an exception if any transform fails, otherwise this will
284+
return a None value for each transform that failed
269285
sdk_options: dict, optional
270286
Dictionary of options that will be passed to the Parameter Store get_parameters_by_path API call
271287
@@ -305,4 +321,11 @@ def get_parameters(
305321
sdk_options["recursive"] = recursive
306322
sdk_options["decrypt"] = decrypt
307323

308-
return DEFAULT_PROVIDERS["ssm"].get_multiple(path, transform=transform, force_fetch=force_fetch, **sdk_options)
324+
return DEFAULT_PROVIDERS["ssm"].get_multiple(
325+
path,
326+
max_age=max_age,
327+
transform=transform,
328+
raise_on_transform_error=raise_on_transform_error,
329+
force_fetch=force_fetch,
330+
**sdk_options
331+
)

0 commit comments

Comments
 (0)