-
Notifications
You must be signed in to change notification settings - Fork 420
Docs: create your own parameters provider - Vault #2250
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
Comments
Hi @dreamorosi! Thank you for pointing that out! |
Hi @dreamorosi, you are 100% right! The return type for this method is wrong, it should be Related to the implementation of the Vault provider as an example, I think Hashicorp Vault is a very specific case when you always have a Are you thinking of implementing this same example in Typescript? Please let us know if you think we can improve this with a more accurate example, it will be awesome!! Thanks so much for taking the time to help us improve our documentation, that's priceless! |
Hey, yes, I was thinking of implementing the same in TS but it's not as simple.
protected abstract _get(
name: string,
options?: unknown
): Promise<string | Uint8Array | undefined>; This means that I'm unsure about how to move forward if I'm being honest, but these are the things I'm considering: On a conceptual level, the get method of any Parameters provider is supposed to return a single value not an object (at least regarding how I think about it). Returning an object would also be problematic for the current implementation of the transform mechanism. With the above in mind, we could implement this method similar to this (pseudo code):
Note that in the code above we are asking the user to also tell us what's the key in the Vault secret that they want to get the value of. This would solve the problems, however I'm unsure about two points:
Sorry for the long message, I know it's a bit all over the place, but I'd really appreciate having this discussion at your own pace/time. |
Andrea, let me step back and correct some information that I got wrong. I was the one who created this documentation and looked at the notes I made at the time and the reason I put the return From the solution you proposed to relax the types, do you mention relaxing the type of the example or the base code? If it's in the example, I think that for now, we can keep it that way, but if it's in the base code, I think that in Python we can change the signature of the function In general, this is a good discussion for all utilities that we allow the customer to extend and build their own provider/code. What are the use cases that customers might have? Are the implementations we have of the base classes too restrictive? We will never cover 100% of cases and we may need to rethink as requests from the community arrive, but at least we will keep this in mind when implementing. Please don't apologize for the message, this is a valid and necessary discussion for the Powertools (all runtimes) to improve the developer experience. Thank you |
|
This is now released under 2.25.0 version! |
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 ofstr
, 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
docker run -e VAULT_DEV_ROOT_TOKEN_ID=abcde --cap-add=IPC_LOCK -p 8200:8200 --name=dev-vault vault
http://0.0.0.0:8200
in your browser and create a secret under thesecret/
path (i.e.my-secret
){ "foo": "bar" }
custom_provider_vault.py
&working_with_own_provider_vault.py
vault_provider = VaultProvider(vault_url="http://0.0.0.0:8200/", vault_token="abcde")
endpoint_comments: Any = vault_provider.get("my-secret", transform="json")
Comments
I find the implementation slightly confusing for two reasons:
self.vault_client.secrets.kv.v2.read_secret
method already returns adict
because the secret is stored as a JSON in the first placejson.dumps
) so that the method returns a string and then in the usage we passtransform="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
The text was updated successfully, but these errors were encountered: