Skip to content
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

Add optional callback-style way to resolve secret values from config #111

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

akaIDIOT
Copy link
Member

@akaIDIOT akaIDIOT commented Dec 6, 2024

Designed to let keyring.get_password drop into any load* function or Configuration instance, currently based on resolved a sing-magic-key mapping in to a secret value, resolved from the keys inside the mapping:

regular.configuration: 42
client:
  username: akaidiot
  password:
    $secret:
      service: github.com
      username: ${client.username}
config = load_name(..., secrets=keyring.get_password)
client = Client(**config.client)
  • badly needs tests
  • draft, subject to change

@@ -194,7 +199,13 @@ def get(self,
return as_type(value)
elif isinstance(value, Mapping):
# wrap value in a Configuration
return self._wrap(value)
value = self._wrap(value)
if self._secrets and self._secrets.matches(value):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: this gets called every step along the config.deeply.nested.keys.foobar way; matches() needs to be cheap 😬

@@ -194,7 +199,13 @@ def get(self,
return as_type(value)
elif isinstance(value, Mapping):
Copy link
Member Author

@akaIDIOT akaIDIOT Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very composition over inheritance approach to an implementation conforming to the Secrets protocol above, is this too much? 🤔

@akaIDIOT akaIDIOT marked this pull request as draft December 6, 2024 19:50
@akaIDIOT akaIDIOT changed the title Draft: Add optional callback-style way to resolve secret values from config Add optional callback-style way to resolve secret values from config Dec 6, 2024
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':
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mypy fails to infer the set being constructed below correctly when this is set to typing.Optional[Secrets], meh 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant