Skip to content

Commit 86619e5

Browse files
refactor(parameters): BaseProvider._get to also support Dict (#3090)
1 parent ef4cd09 commit 86619e5

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def get(
147147
return value
148148

149149
@abstractmethod
150-
def _get(self, name: str, **sdk_options) -> Union[str, bytes]:
150+
def _get(self, name: str, **sdk_options) -> Union[str, bytes, Dict[str, Any]]:
151151
"""
152152
Retrieve parameter value from the underlying parameter store
153153
"""

Diff for: examples/parameters/src/custom_provider_vault.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import json
2-
from typing import Dict
1+
from typing import Any, Dict
32

43
from hvac import Client
54

@@ -8,21 +7,18 @@
87

98
class VaultProvider(BaseProvider):
109
def __init__(self, vault_url: str, vault_token: str) -> None:
11-
1210
super().__init__()
1311

1412
self.vault_client = Client(url=vault_url, verify=False, timeout=10)
1513
self.vault_client.token = vault_token
1614

17-
def _get(self, name: str, **sdk_options) -> str:
18-
15+
def _get(self, name: str, **sdk_options) -> Dict[str, Any]:
1916
# for example proposal, the mountpoint is always /secret
2017
kv_configuration = self.vault_client.secrets.kv.v2.read_secret(path=name)
2118

22-
return json.dumps(kv_configuration["data"]["data"])
19+
return kv_configuration["data"]["data"]
2320

2421
def _get_multiple(self, path: str, **sdk_options) -> Dict[str, str]:
25-
2622
list_secrets = {}
2723
all_secrets = self.vault_client.secrets.kv.v2.list_secrets(path=path)
2824

Diff for: examples/parameters/src/working_with_own_provider_vault.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414

1515

1616
def lambda_handler(event: dict, context: LambdaContext):
17-
1817
try:
1918
# Retrieve a single parameter
20-
endpoint_comments: Any = vault_provider.get("comments_endpoint", transform="json")
19+
endpoint_comments: Any = vault_provider.get("comments_endpoint")
2120

2221
# you can get all parameters using get_multiple and specifying vault mount point
2322
# # for testing purposes we will not use it

0 commit comments

Comments
 (0)