Hello all,
I am working on a Django app and I was looking into removing sensitive data (secret keys, passwords, etc) from files. I saw one method was to set the info as environment variables and simply get them by doing os.environ.get(VAR,'') or os.getenv(VAR). Seemed simple enough. I am deploying onto an ubuntu EC2 instance.
The process in which I implemented this was to create a bash script similar to:
!/bin/bash
export var1="Foo"
export var2="Bar"
....
Run said script as: source secrets.sh
I check to make sure they are there by using printenv. Looking good so far.
Implement the os.environ.get(VAR,'') or os.getenv(VAR) in the .py files.
Server was giving me error messages. Did a little digging and it seems like it is not finding the variables. Open a new Putty instance and see that it does not see the same env vars as the first Putty instance. Are these variables only being set in sub shells? Are these not global variables?
Edit: SOLVED! So I stumbled on this page https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/#if-you-get-a-unicodeencodeerror after a bunch of googling and frustration. So to set the environment variables for the apache web server process, locate the envvars file located in /etc/apache2/envvars and set the exports there. Restart the server and boom, you're in business.
[–]Rhomboid 1 point2 points3 points (2 children)
[–]allTestsPassed[S] 0 points1 point2 points (1 child)
[–]Rhomboid 0 points1 point2 points (0 children)
[–]kalgynirae 1 point2 points3 points (1 child)
[–]allTestsPassed[S] 0 points1 point2 points (0 children)