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

[RFC] Add support for docker-style _FILE environment variables #189

Closed
apollo13 opened this issue Jul 7, 2018 · 3 comments
Closed

[RFC] Add support for docker-style _FILE environment variables #189

apollo13 opened this issue Jul 7, 2018 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@apollo13
Copy link

apollo13 commented Jul 7, 2018

I'd like to add support for docker-style _FILE environment variables. What this would mean basically is the following:

Take this line as an example:

DATABASES = {'default': env.db(default=sqlite_default)}

This will make environ look for a DATABASE_URL and use that. I'd like to extend it to first look for DATABASE_URL_FILE and if that variable exists and is set read the file it points to and use that instead of DATABASE_URL.

The idea here is that stuff like docker swarm secrets are injected as files into your container and I'd need an easy way to reference those. You can find more information about it at https://hub.docker.com/r/_/postgres/ (scroll down to Docker Secrets). Note that while I am referring solely to docker here, the same holds true for any other system which injects secrets as files and not environment variables.

Backwards compatibility wise there should be no issue;

env('ASD_FILE')

would try ASD_FILE_FILE and not read ASD_FILE as file directly...

If you think this is a good idea I'll happily supply a PR; if you are need more convincing please also tell me :)

@valberg
Copy link

valberg commented Jan 24, 2019

@apollo13 have you done any work on this?

@apollo13
Copy link
Author

apollo13 commented Jan 25, 2019 via email

tkdchen pushed a commit to tkdchen/django-environ that referenced this issue Oct 6, 2019
Hopefully this saves time for new users of django-configuration (like myself), who "just needed" to lazily evaluate a string inside a dictionary.

This doubles as an example for `RAVEN_CONFIG` which was the whole reason I was here in the first place... The actual problem I faced was that a setting remains of type `values.Value` when nested inside a dictionary. Which results in a weird issues like this:

```
2018-02-24T20:59:26.125208+00:00 app[web.1]: Traceback (most recent call last):
2018-02-24T20:59:26.125364+00:00 app[web.1]:     self.client.http_context(self.get_http_context(environ))
2018-02-24T20:59:26.125215+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/raven/middleware.py", line 98, in __call__
2018-02-24T20:59:26.125368+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/raven/contrib/django/models.py", line 54, in <lambda>
2018-02-24T20:59:26.125482+00:00 app[web.1]:     __getattr__ = lambda x, o: getattr(get_client(), o)
2018-02-24T20:59:26.125486+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/raven/contrib/django/models.py", line 134, in get_client
2018-02-24T20:59:26.125613+00:00 app[web.1]:     instance = Client(**options)
2018-02-24T20:59:26.125618+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/raven/contrib/django/client.py", line 147, in __init__
2018-02-24T20:59:26.125769+00:00 app[web.1]:     Client.__init__(self, *args, **kwargs)
2018-02-24T20:59:26.125771+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/raven/base.py", line 171, in __init__
2018-02-24T20:59:26.125927+00:00 app[web.1]:     self.set_dsn(dsn, transport)
2018-02-24T20:59:26.125929+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/raven/base.py", line 251, in set_dsn
2018-02-24T20:59:26.126063+00:00 app[web.1]:     if dsn not in self._transport_cache:
2018-02-24T20:59:26.126076+00:00 app[web.1]: TypeError: unhashable type: 'Value'
```
@sergeyklay sergeyklay added the enhancement New feature or request label Sep 7, 2021
SmileyChris added a commit to SmileyChris/django-environ that referenced this issue Sep 13, 2021
@sergeyklay sergeyklay self-assigned this Sep 15, 2021
@sergeyklay
Copy link
Collaborator

This is resolved in main branch. Thank you for the report, and for helping us make django-environ better. And I am sorry about the delay.

mehdy pushed a commit to mehdy/django-environ that referenced this issue Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants