feat(parameters): add adaptive types to SecretsProvider #1411
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of your changes
As discussed in the linked issue, the return types for the
SecretsProvider
part of the Parameters utility were fairly generic and could be improved by applying some heuristics based on the method used and some of the parameters passed. In addition to that, we could also provide a way for users to explicitly set the return type when they know the shape of the values they are retrieving.This PR introduces new adaptive types for the
getSecret()
function as well as its class-based corespondent SecretsProvider.get()`.The new types use generics and modify the return type of the functions/methods based on the arguments passed to them or based on an explicitly set type.
For instance, if users pass transform:
json
, then we can assume that the return type should be an object (Record<K, V>
). Conversely, if no transform or abinary
(base64) transform is applied, the result will be astring
.Finally, if the user doesn't specify any transform then, given tht SecretsManager is able to store both
SecretString
andSecretBinary
data types, then we can only narrow down the return type to one ofstring
orUint8Array
.There are however also cases in which users might know more about the values they are retrieving than the compiler does, and for those instances this PR introduces the ability to specify the return type while using either the function or method like so:
In the example above the
value
constant will have typenumber
, this is because the user has specified a type and so this will take precedence over any type-heuristic we do behind the scenes.Once merged this PR closes #1409
Related issues, RFCs
Issue number: #1409
Checklist
Breaking change checklist
Is it a breaking change?: NO
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.