mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-22 06:28:41 +02:00
Changed how secret key is generated on deploy
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
import getpass
|
||||
import os
|
||||
from os.path import isfile
|
||||
import secrets
|
||||
import shutil
|
||||
import string
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
@@ -81,6 +83,10 @@ class DeployCommand(Command):
|
||||
"--admin-username", default="admin",
|
||||
help="Username of the initial super administrator"
|
||||
)
|
||||
self._parser.add_argument(
|
||||
"--secret-key-length", default=60, type=int,
|
||||
help="Specify the length of the secret key"
|
||||
)
|
||||
|
||||
def _exec_django_command(self, name, cwd, *args):
|
||||
"""Run a django command for the freshly created project
|
||||
@@ -156,6 +162,14 @@ class DeployCommand(Command):
|
||||
official_exts = ModoAPIClient(url).list_extensions()
|
||||
return [extension["name"] for extension in official_exts]
|
||||
|
||||
def _generate_secret_key(self, secret_key_length):
|
||||
"""Generate a secret key since the one generated by django
|
||||
is marked as insecure.
|
||||
"""
|
||||
c = string.ascii_letters + string.digits + string.punctuation
|
||||
secret_key = ''.join(secrets.choice(c) for i in range(secret_key_length))
|
||||
return secret_key
|
||||
|
||||
def find_extra_settings(self, extensions):
|
||||
"""Install one or more extensions.
|
||||
|
||||
@@ -233,7 +247,7 @@ class DeployCommand(Command):
|
||||
tpl = self._render_template(
|
||||
"%s/settings.py.tpl" % self._templates_dir, {
|
||||
"db_connections": connections,
|
||||
"secret_key": mod.settings.SECRET_KEY,
|
||||
"secret_key": _generate_secret_key(parsed_args.secret_key_length),
|
||||
"name": parsed_args.name,
|
||||
"allowed_host": allowed_host,
|
||||
"lang": parsed_args.lang,
|
||||
|
||||
Reference in New Issue
Block a user