Commit 2aa93d0d authored by Elena Grandi's avatar Elena Grandi
Browse files

Generate FUSS_MANAGER_SECRET_KEY when installing

parent fc443839
octonet (0.2.55-1) testing; urgency=medium
* Generate FUSS_MANAGER_SECRET_KEY when installing
-- Elena Grandi <elena@truelite.it> Fri, 22 Nov 2019 13:06:18 +0100
octonet (0.2.54-1) testing; urgency=medium
[ Mark Caglienzi ]
......
......@@ -11,6 +11,9 @@ ALLOWED_HOSTS = ["*"]
#makesecret: {GENERATED_SECRET} will be replaced by a newly generated one on package installation
SECRET_KEY = '{GENERATED_SECRET}'
#makesecret: {GENERATED_SECRET} will be replaced by a newly generated one on package installation
FUSS_MANAGER_SECRET_KEY = '{MANAGER_GENERATED_SECRET}'
# Uncomment the following two lines to activate logging to
# /var/log/octonet/octonet.log
#with open("/etc/octonet_logging.conf", "rt") as fd:
......
......@@ -14,6 +14,7 @@ case "$1" in
chown octonet:root /etc/octonet.conf
chmod 0640 /etc/octonet.conf
cd /usr/share/octonet/ && su octonet -s /bin/sh -c "./manage.py makesecret /etc/octonet.conf"
cd /usr/share/octonet/ && su octonet -s /bin/sh -c "./manage.py makesecret --placeholder='{MANAGER_GENERATED_SECRET}' /etc/octonet.conf"
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
......
......@@ -3,9 +3,7 @@ from django.core.management.base import BaseCommand, CommandError
from django.utils.crypto import get_random_string
import os, sys
PLACEHOLDER = "{GENERATED_SECRET}"
def get_lines_to_changes(pathname):
def get_lines_to_changes(pathname, placeholder):
import ast
with open(pathname, "rt") as fd:
......@@ -14,7 +12,7 @@ def get_lines_to_changes(pathname):
replace_lines = set()
for node in ast.walk(code):
if not isinstance(node, ast.Str): continue
if node.s != PLACEHOLDER: continue
if node.s != placeholder: continue
replace_lines.add(node.lineno)
return replace_lines
......@@ -23,6 +21,9 @@ class Command(BaseCommand):
help = 'Update the secret key in the default config.'
def add_arguments(self, parser):
parser.add_argument('--placeholder',
default= "{GENERATED_SECRET}",
help='Placeholder to change.')
parser.add_argument('pathname',
help='Configuration file to edit.')
......@@ -36,14 +37,14 @@ class Command(BaseCommand):
print("{} does not exist".format(configfile), file=sys.stderr)
sys.exit(1)
replace_lines = get_lines_to_changes(configfile)
replace_lines = get_lines_to_changes(configfile, options['placeholder'])
if not replace_lines: return
new_content = []
with open(configfile, "rt") as fd:
for lineno, line in enumerate(fd, start=1):
if lineno in replace_lines:
line = line.replace(PLACEHOLDER, secret_key)
line = line.replace(options['placeholder'], secret_key)
new_content.append(line)
with open(configfile, "wt") as fd:
......
......@@ -13,7 +13,7 @@ def list_locale_files():
setup(
name='octonet',
description='OctoNet',
version='0.2.54',
version='0.2.55',
license='GPL3',
author='Truelite S.r.l.',
author_email='info@truelite.it',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment