Skip to content

Allow custom environment variable prefixes in settings provider #253

Open
@jeremiahrose

Description

@jeremiahrose

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions