From d5f3b4e1def2dce32ff9ace761bc691bded423b8 Mon Sep 17 00:00:00 2001 From: Cy Date: Sat, 30 May 2020 08:02:36 +0000 Subject: [PATCH] Out of repo settings Files that contain private information like passwords, secrets, and host names shouldn't be under revision control. --- INSTALL.md | 2 +- brutaldon/settings.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 1b9c146..1aeef3f 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -25,7 +25,7 @@ This will depend on your server setup, and you should consult [Deploying Django] One common step would be to install dependencies like this: `PIPENV_VENV_IN_PROJECT=1 pipenv install`. This will install dependencies within the project folder. -Then edit brutaldon/settings.py. You definitely need to change the values of SECRET_KEY and ALLOWED_HOSTS. Also edit the database parameters to match the database you chose. Then run `pipenv run python ./manage.py migrate` to populate the database. +Then create the file ~/.config/brutaldon_settings.py which overrides anything in brutaldon/settings.py. You definitely need to override SECRET_KEY and ALLOWED_HOSTS. Also edit the database parameters to match the database you chose. Then run `pipenv run python ./manage.py migrate` to populate the database. I installed brutaldon with Apache and mod_wsgi. If you installed brutaldon in /usr/local/share/, you'd add config lines something like this to the virtual host brutaldon is installed in. diff --git a/brutaldon/settings.py b/brutaldon/settings.py index 7e645ee..9475cfc 100644 --- a/brutaldon/settings.py +++ b/brutaldon/settings.py @@ -205,3 +205,37 @@ GAB_RICKROLL_URL = "https://invidio.us/watch?v=dQw4w9WgXcQ" # Version number displayed on about page BRUTALDON_VERSION = "2.14.1" + +# Load custom settings outside repository tracked files, so private settings +# don't get added to the repository +import sys +def paths(): + sys.path.append('???') + try: + from xdg import XDG_CONFIG_HOME, XDG_CONFIG_DIRS + except ImportError: + try: + from pathlib import Path + except ImportError: + home = os.environ['home'] + else: + home = Path.home() + sys.path[-1] = os.path.join(home, ".config") + yield + sys.path[-1] = home + yield + else: + sys.path[-1] = XDG_CONFIG_HOME + yield + for directory in XDG_CONFIG_DIRS: + sys.path[-1] = directory + yield + finally: + sys.path.pop(-1) + +for _ in paths(): + try: + from brutaldon_settings import * + except ImportError: pass + else: + break