Skip to content

refactor(parameters): BaseProvider._get to also support Dict #3090

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

Merged
merged 1 commit into from
Sep 14, 2023
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
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
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