Mercurial > piecrust2
comparison piecrust/commands/builtin/admin.py @ 597:79a31a3c947b
admin: Better production config for FoodTruck, provide proper first site.
* Use a `settings` object to configure Flask.
* Accept an `app.cfg` file in the admin folder to configure Flask.
* Get a proper first site name when the cookie isn't set yet.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 20 Jan 2016 21:39:18 -0800 |
parents | b884bef3e611 |
children | effbc78b5528 |
comparison
equal
deleted
inserted
replaced
596:e2c91ba44d6c | 597:79a31a3c947b |
---|---|
37 if not hasattr(ctx.args, 'sub_func'): | 37 if not hasattr(ctx.args, 'sub_func'): |
38 return self._runFoodTruck(ctx) | 38 return self._runFoodTruck(ctx) |
39 return ctx.args.sub_func(ctx) | 39 return ctx.args.sub_func(ctx) |
40 | 40 |
41 def _runFoodTruck(self, ctx): | 41 def _runFoodTruck(self, ctx): |
42 from foodtruck import settings | |
43 settings.FOODTRUCK_CMDLINE_MODE = True | |
42 from foodtruck.main import run_foodtruck | 44 from foodtruck.main import run_foodtruck |
43 run_foodtruck(debug=ctx.args.debug) | 45 run_foodtruck(debug=ctx.args.debug) |
44 | 46 |
45 def _initFoodTruck(self, ctx): | 47 def _initFoodTruck(self, ctx): |
46 import getpass | 48 import getpass |
59 binpw = admin_password.encode('utf8') | 61 binpw = admin_password.encode('utf8') |
60 hashpw = bcrypt.hashpw(binpw, bcrypt.gensalt()).decode('utf8') | 62 hashpw = bcrypt.hashpw(binpw, bcrypt.gensalt()).decode('utf8') |
61 admin_password = hashpw | 63 admin_password = hashpw |
62 | 64 |
63 ft_config = """ | 65 ft_config = """ |
64 foodtruck: | |
65 secret_key: %(secret_key)s | |
66 security: | 66 security: |
67 username: %(username)s | 67 username: %(username)s |
68 # You can generate another hashed password with `chef admin genpass`. | 68 # You can generate another hashed password with `chef admin genpass`. |
69 password: %(password)s | 69 password: %(password)s |
70 """ | 70 """ |
71 ft_config = ft_config % { | 71 ft_config = ft_config % { |
72 'secret_key': secret_key, | |
73 'username': admin_username, | 72 'username': admin_username, |
74 'password': admin_password | 73 'password': admin_password |
75 } | 74 } |
76 with open('foodtruck.yml', 'w', encoding='utf8') as fp: | 75 with open('foodtruck.yml', 'w', encoding='utf8') as fp: |
77 fp.write(ft_config) | 76 fp.write(ft_config) |
77 | |
78 flask_config = """ | |
79 secret_key = '%(secret_key)s' | |
80 """ | |
81 flask_config = flask_config % {'secret_key': secret_key} | |
82 with open('app.cfg', 'w', encoding='utf8') as fp: | |
83 fp.write(flask_config) | |
78 | 84 |
79 def _generatePassword(self, ctx): | 85 def _generatePassword(self, ctx): |
80 import bcrypt | 86 import bcrypt |
81 binpw = ctx.args.password.encode('utf8') | 87 binpw = ctx.args.password.encode('utf8') |
82 hashpw = bcrypt.hashpw(binpw, bcrypt.gensalt()).decode('utf8') | 88 hashpw = bcrypt.hashpw(binpw, bcrypt.gensalt()).decode('utf8') |