Skip to content

Commit

Permalink
refactor(parameters): BaseProvider._get to also support Dict (#3090)
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrodamascena authored Sep 14, 2023
1 parent ef4cd09 commit 86619e5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion aws_lambda_powertools/utilities/parameters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def get(
return value

@abstractmethod
def _get(self, name: str, **sdk_options) -> Union[str, bytes]:
def _get(self, name: str, **sdk_options) -> Union[str, bytes, Dict[str, Any]]:
"""
Retrieve parameter value from the underlying parameter store
"""
Expand Down
10 changes: 3 additions & 7 deletions examples/parameters/src/custom_provider_vault.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
from typing import Dict
from typing import Any, Dict

from hvac import Client

Expand All @@ -8,21 +7,18 @@

class VaultProvider(BaseProvider):
def __init__(self, vault_url: str, vault_token: str) -> None:

super().__init__()

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

def _get(self, name: str, **sdk_options) -> str:

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

return json.dumps(kv_configuration["data"]["data"])
return kv_configuration["data"]["data"]

def _get_multiple(self, path: str, **sdk_options) -> Dict[str, str]:

list_secrets = {}
all_secrets = self.vault_client.secrets.kv.v2.list_secrets(path=path)

Expand Down
3 changes: 1 addition & 2 deletions examples/parameters/src/working_with_own_provider_vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@


def lambda_handler(event: dict, context: LambdaContext):

try:
# Retrieve a single parameter
endpoint_comments: Any = vault_provider.get("comments_endpoint", transform="json")
endpoint_comments: Any = vault_provider.get("comments_endpoint")

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

0 comments on commit 86619e5

Please sign in to comment.