Add optional callback-style way to resolve secret values from config#111
Add optional callback-style way to resolve secret values from config#111
Conversation
confidence/models.py
Outdated
| # wrap value in a Configuration | ||
| return self._wrap(value) | ||
| value = self._wrap(value) | ||
| if self._secrets and self._secrets.matches(value): |
There was a problem hiding this comment.
NB: this gets called every step along the config.deeply.nested.keys.foobar way; matches() needs to be cheap 😬
There was a problem hiding this comment.
Would this lend itself to a match statement, allowing the secrets instance to supply its own match args? 🤔
confidence/models.py
Outdated
| @@ -194,7 +199,13 @@ def get(self, | |||
| return as_type(value) | |||
| elif isinstance(value, Mapping): | |||
There was a problem hiding this comment.
As this has been hooked into here: current implementation requires any and all implementations to utilize at least some kind of mapping / dict / subtree to implement this. Do we want this kind restriction? Do we want to implement any alternatives right away or maybe at a later stage?
There was a problem hiding this comment.
Yes, yes, this need many comments on what / why the f things are as they are, soon™
| callback=callback, | ||
| single_key=single_key, | ||
| args=args, | ||
| ) |
There was a problem hiding this comment.
This is a very composition over inheritance approach to an implementation conforming to the Secrets protocol above, is this too much? 🤔
confidence/models.py
Outdated
| def merge(*sources: typing.Mapping[str, typing.Any], missing: typing.Any = None) -> 'Configuration': | ||
| def merge(*sources: typing.Mapping[str, typing.Any], | ||
| missing: typing.Any = None, | ||
| secrets: typing.Any = None) -> 'Configuration': |
There was a problem hiding this comment.
Mypy fails to infer the set being constructed below correctly when this is set to typing.Optional[Secrets], meh 🤔
|
Okay I looked a little into this whole YAML loading stuff and I might have found a way to make the syntax more clean! You can use YAML tags to get this syntax: This way, you get rid of the extra indentation and make it look a bit easier on the eye. You can then load it in python with something like this: What do you think? I believe you can integrate something like this but let me know if this is not really what you were looking for :) |
Interesting idea! I'll read up on the constructs a bit, definitely has potential to lose a level of indentation, provided users are going to 'get' the syntax. It is very explicit though, I like that :D (and, just remembered there were thoughts on supporting toml, as that's becoming default in py-land, but not necessarily part of this PR) |
c9bd939 to
4d0d029
Compare
Designed to let
keyring.get_passworddrop into anyload*function orConfigurationinstance, currently based on resolved a sing-magic-key mapping in to a secret value, resolved from the keys inside the mapping: