Skip to content

Docs: create your own parameters provider - Vault #2250

Closed
@dreamorosi

Description

@dreamorosi

What were you searching in the docs?

I am looking at creating my own Parameters provider and followed the example that shows how to create a provider for HashiCorp Vault. I'm doing this work because I'm writing a similar piece for the TS version.

The VaultProvider.get method has a return type of str, however after testing the code with Vault, I think it's not correct as at the best of my knowledge you can't store plain text strings into Vault and the SDK returns at least dictionary (key-value).

Steps to reproduce

  1. Run Vault in dev mode using Docker docker run -e VAULT_DEV_ROOT_TOKEN_ID=abcde --cap-add=IPC_LOCK -p 8200:8200 --name=dev-vault vault
  2. Open http://0.0.0.0:8200 in your browser and create a secret under the secret/ path (i.e. my-secret)
  3. The UI will allow you to create only a key-value secret and not a string (see image below) - so create one (i.e. { "foo": "bar" }

image

  1. Copy the two files in the docs: custom_provider_vault.py & working_with_own_provider_vault.py
  2. Update the following fields:
  • L13 -> vault_provider = VaultProvider(vault_url="http://0.0.0.0:8200/", vault_token="abcde")
  • L20 -> endpoint_comments: Any = vault_provider.get("my-secret", transform="json")
  1. Run the code

Comments

I find the implementation slightly confusing for two reasons:

  1. The self.vault_client.secrets.kv.v2.read_secret method already returns a dict because the secret is stored as a JSON in the first place
  2. Before returning the secret we stringify it (json.dumps) so that the method returns a string and then in the usage we pass transform="json" to transform it back to a dict, which seems counterintuitive.

Is this related to an existing documentation section?

https://awslabs.github.io/aws-lambda-powertools-python/2.15.0/utilities/parameters/#create-your-own-provider

How can we improve?

I think we should review the return type, and potentially the implementation of the VaultProvider.get method.

Got a suggestion in mind?

No response

Acknowledgment

  • I understand the final update might be different from my proposed suggestion, or refused.

Metadata

Metadata

Labels

documentationImprovements or additions to documentationrevisit-in-3-monthsRequires more customers feedback before making or revisiting a decision

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions