From f67d4505d3968aa8b21bd558675b25caaa58fb33 Mon Sep 17 00:00:00 2001 From: Michael Polidori Date: Mon, 16 Dec 2019 16:56:10 -0500 Subject: [PATCH] [fix][s]: replaces paster make-config --- ckan/cli/generate.py | 36 +++++++++++++++++++++++++++++++++ ckan/config/deployment.ini_tmpl | 8 ++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/ckan/cli/generate.py b/ckan/cli/generate.py index acb09817cdc..a8636ce468d 100644 --- a/ckan/cli/generate.py +++ b/ckan/cli/generate.py @@ -3,6 +3,9 @@ import os import sys import click +import uuid +import random +import string from ckan.cli import error_shout @@ -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) diff --git a/ckan/config/deployment.ini_tmpl b/ckan/config/deployment.ini_tmpl index 0da5e347cee..398ea656f55 100644 --- a/ckan/config/deployment.ini_tmpl +++ b/ckan/config/deployment.ini_tmpl @@ -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