diff --git a/.gitignore b/.gitignore index ec0bae4220..e304877626 100644 --- a/.gitignore +++ b/.gitignore @@ -30,7 +30,10 @@ local_settings.py # Local media storage (only when running in development mode) InvenTree/media -# Ignore PyCharm project configuration +# Key file +secret_key.txt + +# Ignore python IDE project configuration .idea/ # Coverage reports diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 813d0d8ad4..65581eb4e6 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -21,8 +21,9 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -# TODO: remove this -SECRET_KEY = 'oc2z%5)lu#jsxi#wpg)700z@v48)2aa_yn(a(3qg!z!fw&tr9f' +key_file = open(os.path.join(BASE_DIR, 'secret_key.txt'), 'r') + +SECRET_KEY = key_file.read().strip() # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True diff --git a/InvenTree/key.py b/InvenTree/key.py new file mode 100644 index 0000000000..c28b9c6a30 --- /dev/null +++ b/InvenTree/key.py @@ -0,0 +1,24 @@ +# Generate a SECRET_KEY file + +import random +import string +import os + +fn = 'secret_key.txt' + + +def generate_key(): + options = string.digits + string.ascii_letters + string.punctuation + key = ''.join([random.choice(options) for i in range(50)]) + return key + + +if __name__ == '__main__': + + # Ensure key file is placed in same directory as this script + path = os.path.dirname(os.path.realpath(__file__)) + key_file = os.path.join(path, fn) + + with open(key_file, 'w') as kf: + kf.write(generate_key()) + print('Generated SECRET_KEY to {f}'.format(f=key_file)) diff --git a/Makefile b/Makefile index 831ab4ff3a..7586b678a4 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,9 @@ migrate: install: # TODO: replace this with a proper setup.py pip install -U -r requirements/base.txt + + # Generate a secret key + python InvenTree/key.py setup: install migrate