Skip to content

Commit

Permalink
[fix][s]: replaces paster make-config
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolidori committed Dec 16, 2019
1 parent fbab8f5 commit f67d450
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
36 changes: 36 additions & 0 deletions ckan/cli/generate.py
Expand Up @@ -3,6 +3,9 @@
import os
import sys
import click
import uuid
import random
import string
from ckan.cli import error_shout


Expand Down Expand Up @@ -76,3 +79,36 @@ def extension(output_dir):

cookiecutter(template_loc, no_input=True, extra_context=context,
output_dir=output_dir)


@generate.command(name=u'config', short_help=u'Create config from template.')
@click.option(u'-o', u'--output-dir', help=u'Location to put the generated '
u'template.', default=u'.')
def make_config(output_dir):
if not any(name in output_dir for name in
['development.ini', 'production.ini']):
print('\nERROR: File name must be development.ini or production.ini')
sys.exit(1)

cur_loc = os.path.dirname(os.path.abspath(__file__))
os.chdir(cur_loc)
os.chdir('../config')
template_loc = os.getcwd() + '/deployment.ini_tmpl'
template_variables = {
'app_instance_uuid': uuid.uuid4(),
'app_instance_secret': ''.join(
random.SystemRandom().choice(string.ascii_letters + string.digits)
for _ in range(25))
}

with open(template_loc, 'r') as file_in:
template = string.Template(file_in.read())
print(output_dir)

try:
with open(output_dir, 'w') as file_out:
file_out.writelines(template.substitute(template_variables))

except IOError as e:
error_shout(e)
sys.exit(1)
8 changes: 4 additions & 4 deletions ckan/config/deployment.ini_tmpl
Expand Up @@ -29,13 +29,13 @@ cache_dir = /tmp/%(ckan.site_id)s/
beaker.session.key = ckan

# This is the secret token that the beaker library uses to hash the cookie sent
# to the client. `paster make-config` generates a unique value for this each
# to the client. `ckan generate config` generates a unique value for this each
# time it generates a config file.
beaker.session.secret = ${app_instance_secret}
beaker.session.secret = $app_instance_secret

# `paster make-config` generates a unique value for this each time it generates
# `ckan generate config` generates a unique value for this each time it generates
# a config file.
app_instance_uuid = ${app_instance_uuid}
app_instance_uuid = $app_instance_uuid

# repoze.who config
who.config_file = %(here)s/who.ini
Expand Down

0 comments on commit f67d450

Please sign in to comment.