mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 21:43:21 +00:00
Source LOCAL_DATABASE_PASSWORD and INITIAL_PASSWORD_SALT from the secrets file. Fix the creation of pgpass file. Tim's note: This will definitely break the original purpose of the tool but it should be pretty easy to add that back as an option. (imported from commit 8ab31ea2b7cbc80a4ad2e843a2529313fad8f5cf)
71 lines
2.3 KiB
Python
Executable File
71 lines
2.3 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# This tools generates local_settings_generated.py using the template
|
|
|
|
import sys, os, os.path
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
|
|
|
|
from django.utils.crypto import get_random_string
|
|
from zerver.lib.utils import generate_random_token
|
|
|
|
os.chdir(os.path.join(os.path.dirname(__file__), '..', '..'))
|
|
|
|
OUTPUT_SETTINGS_FILENAME = "zproject/dev-secrets.conf"
|
|
CAMO_CONFIG_FILENAME = '/etc/default/camo'
|
|
|
|
AUTOGENERATED_SETTINGS = ['shared_secret', 'avatar_salt', 'rabbitmq_password', 'local_database_password',
|
|
'initial_password_salt']
|
|
|
|
EMPTY_SETTINGS = ['deployment_role_key', 'mandrill_api_key', 'mailchimp_api_key', 'email_password', 's3_key', 's3_secret_key',
|
|
'google_oauth2_client_secret', 'dev_google_oauth2_client_secret']
|
|
|
|
def generate_camo_config_file(camo_key):
|
|
camo_config = """ENABLED=yes
|
|
PORT=9292
|
|
CAMO_KEY=%s
|
|
""" % (camo_key,)
|
|
with open(CAMO_CONFIG_FILENAME, 'w') as camo_file:
|
|
camo_file.write(camo_config)
|
|
print "Generated Camo config file %s" % (CAMO_CONFIG_FILENAME,)
|
|
|
|
def generate_django_secretkey():
|
|
# Secret key generation taken from Django's startproject.py
|
|
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
|
|
return get_random_string(50, chars)
|
|
|
|
def generate_secrets(development=False):
|
|
lines = ['[secrets]\n']
|
|
|
|
def config_line(var, value):
|
|
return "%s = %s\n" % (var, value)
|
|
|
|
for name in AUTOGENERATED_SETTINGS:
|
|
lines.append(config_line(name, generate_random_token(64)))
|
|
|
|
lines.append(config_line('secret_key', generate_django_secretkey()))
|
|
camo_key = get_random_string(64)
|
|
lines.append(config_line('camo_key', camo_key))
|
|
if not development:
|
|
# Write the Camo config file directly
|
|
generate_camo_config_file(camo_key)
|
|
|
|
for name in EMPTY_SETTINGS:
|
|
lines.append(config_line(name, ''))
|
|
|
|
out = open(OUTPUT_SETTINGS_FILENAME, 'w')
|
|
out.write("".join(lines))
|
|
out.close()
|
|
|
|
print "Generated %s with auto-generated secrets!" % (OUTPUT_SETTINGS_FILENAME,)
|
|
|
|
if __name__ == '__main__':
|
|
|
|
development = False
|
|
extra_args = sys.argv[1:]
|
|
|
|
if len(extra_args) and extra_args[0] in ('-d', '--development'):
|
|
development = True
|
|
|
|
generate_secrets(development)
|