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

Allow custom environment variable prefixes in settings provider #253

Open
jeremiahrose opened this issue Oct 24, 2022 · 3 comments · May be fixed by #258
Open

Allow custom environment variable prefixes in settings provider #253

jeremiahrose opened this issue Oct 24, 2022 · 3 comments · May be fixed by #258

Comments

@jeremiahrose
Copy link

Following on from the discourse conversation here.

When using the settings provider source, it currently isn't possible to assign a prefix to an environment variable name without also having the prefix in the internal setting name. We have written a patch and it seems straightforward enough to allow an optional prefix to be configured in the register_provider block like so:

Application.register_provider(:settings, from: :dry_system) do
  prefix { 'SOME_PREFIX_' }

  settings do
    setting :database_url, constructor: Types::String.constrained(filled: true)
end

I would like to submit a PR for this soon, if maintainers feel it would be helpful!

@solnic also mentioned that:

Having ability to have nested keys from env would be great too like STRIPE__API_KEY would be turned into settings.stripe.api_key.

I agree that would be a nice feature, so I would be happy to implement that too.

@jeremiahrose
Copy link
Author

Sorry about bug label, I can't seem to remove it. :(

@solnic solnic added enhancement and removed bug labels Oct 24, 2022
@alassek
Copy link
Contributor

alassek commented Oct 25, 2022

I would have expected the prefix option to be passed in via register_provider kwarg, I am guessing that you chose a provider method so that the implementation would be limited to the Settings provider?

I wonder if it would be helpful to have some sort of options pass-through from the register_provider method into the provider initialization.

@jeremiahrose
Copy link
Author

@alassek we went for a configuration option instead, PR up here: #258

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