Mercurial > piecrust2
annotate piecrust/commands/builtin/admin.py @ 762:c84647485ab2
admin: Fix crash when running the `admin` command.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 30 Jun 2016 22:37:16 -0700 |
parents | dba53f0f7671 |
children | 5e91bc0e3b4d |
rev | line source |
---|---|
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 import os |
656
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
2 import os.path |
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 import logging |
653
466bbddd121e
admin: Run the asset pipeline before showing the admin panel.
Ludovic Chabant <ludovic@chabant.com>
parents:
640
diff
changeset
|
4 from piecrust import CACHE_DIR |
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 from piecrust.commands.base import ChefCommand |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 logger = logging.getLogger(__name__) |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 class AdministrationPanelCommand(ChefCommand): |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 def __init__(self): |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 super(AdministrationPanelCommand, self).__init__() |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 self.name = 'admin' |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 self.description = "Manages the PieCrust administration panel." |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 self.requires_website = False |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 def setupParser(self, parser, app): |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 subparsers = parser.add_subparsers() |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 p = subparsers.add_parser( |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 'init', |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 help="Creates a new administration panel website.") |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 p.set_defaults(sub_func=self._initFoodTruck) |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 p = subparsers.add_parser( |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 'genpass', |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 help=("Generates the hashed password for use as an " |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 "admin password")) |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
30 p.add_argument('password', help="The password to hash.") |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 p.set_defaults(sub_func=self._generatePassword) |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
32 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 p = subparsers.add_parser( |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 'run', |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 help="Runs the administrative panel website.") |
619
200c7063affa
admin: Change the default admin server port to 8090, add `--port` option.
Ludovic Chabant <ludovic@chabant.com>
parents:
611
diff
changeset
|
36 p.add_argument( |
200c7063affa
admin: Change the default admin server port to 8090, add `--port` option.
Ludovic Chabant <ludovic@chabant.com>
parents:
611
diff
changeset
|
37 '-p', '--port', |
200c7063affa
admin: Change the default admin server port to 8090, add `--port` option.
Ludovic Chabant <ludovic@chabant.com>
parents:
611
diff
changeset
|
38 help="The port for the administrative panel website.", |
200c7063affa
admin: Change the default admin server port to 8090, add `--port` option.
Ludovic Chabant <ludovic@chabant.com>
parents:
611
diff
changeset
|
39 default=8090) |
200c7063affa
admin: Change the default admin server port to 8090, add `--port` option.
Ludovic Chabant <ludovic@chabant.com>
parents:
611
diff
changeset
|
40 p.add_argument( |
200c7063affa
admin: Change the default admin server port to 8090, add `--port` option.
Ludovic Chabant <ludovic@chabant.com>
parents:
611
diff
changeset
|
41 '-a', '--address', |
200c7063affa
admin: Change the default admin server port to 8090, add `--port` option.
Ludovic Chabant <ludovic@chabant.com>
parents:
611
diff
changeset
|
42 help="The host for the administrative panel website.", |
200c7063affa
admin: Change the default admin server port to 8090, add `--port` option.
Ludovic Chabant <ludovic@chabant.com>
parents:
611
diff
changeset
|
43 default='localhost') |
656
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
44 p.add_argument( |
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
45 '--no-assets', |
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
46 help="Don't process and monitor the asset folder(s).", |
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
47 dest='monitor_assets', |
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
48 action='store_false') |
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
49 p.set_defaults(sub_func=self._runFoodTruck) |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
50 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
51 def checkedRun(self, ctx): |
762
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
52 if ctx.app.root_dir is None: |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
53 raise SiteNotFoundError(theme=ctx.app.theme_site) |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
54 |
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
55 if not hasattr(ctx.args, 'sub_func'): |
762
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
56 ctx.parser.parse_args(['admin', '--help']) |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
57 return |
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
58 return ctx.args.sub_func(ctx) |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
59 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
60 def _runFoodTruck(self, ctx): |
656
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
61 # See `_run_sse_check` in `piecrust.serving.wrappers` for an explanation |
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
62 # of this check. |
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
63 if (ctx.args.monitor_assets and ( |
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
64 not ctx.args.debug or |
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
65 os.environ.get('WERKZEUG_RUN_MAIN') == 'true')): |
762
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
66 from piecrust.app import PieCrustFactory |
656
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
67 from piecrust.serving.procloop import ProcessingLoop |
762
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
68 appfactory = PieCrustFactory( |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
69 ctx.app.root_dir, |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
70 cache=ctx.app.cache.enabled, |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
71 cache_key=ctx.app.cache_key, |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
72 config_variant=ctx.config_variant, |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
73 config_values=ctx.config_values, |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
74 debug=ctx.app.debug, |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
75 theme_site=ctx.app.theme_site) |
656
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
76 out_dir = os.path.join(ctx.app.root_dir, CACHE_DIR, 'foodtruck', 'server') |
762
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
77 proc_loop = ProcessingLoop(appfactory, out_dir) |
656
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
78 proc_loop.start() |
653
466bbddd121e
admin: Run the asset pipeline before showing the admin panel.
Ludovic Chabant <ludovic@chabant.com>
parents:
640
diff
changeset
|
79 |
597
79a31a3c947b
admin: Better production config for FoodTruck, provide proper first site.
Ludovic Chabant <ludovic@chabant.com>
parents:
588
diff
changeset
|
80 from foodtruck import settings |
79a31a3c947b
admin: Better production config for FoodTruck, provide proper first site.
Ludovic Chabant <ludovic@chabant.com>
parents:
588
diff
changeset
|
81 settings.FOODTRUCK_CMDLINE_MODE = True |
611
906cc2520773
admin: Use the app directory, not the cwd, in case of `--root`.
Ludovic Chabant <ludovic@chabant.com>
parents:
601
diff
changeset
|
82 settings.FOODTRUCK_ROOT = ctx.app.root_dir |
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
83 from foodtruck.main import run_foodtruck |
619
200c7063affa
admin: Change the default admin server port to 8090, add `--port` option.
Ludovic Chabant <ludovic@chabant.com>
parents:
611
diff
changeset
|
84 run_foodtruck( |
200c7063affa
admin: Change the default admin server port to 8090, add `--port` option.
Ludovic Chabant <ludovic@chabant.com>
parents:
611
diff
changeset
|
85 host=ctx.args.address, |
200c7063affa
admin: Change the default admin server port to 8090, add `--port` option.
Ludovic Chabant <ludovic@chabant.com>
parents:
611
diff
changeset
|
86 port=ctx.args.port, |
200c7063affa
admin: Change the default admin server port to 8090, add `--port` option.
Ludovic Chabant <ludovic@chabant.com>
parents:
611
diff
changeset
|
87 debug=ctx.args.debug) |
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
88 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
89 def _initFoodTruck(self, ctx): |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
90 import getpass |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
91 import bcrypt |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
92 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
93 secret_key = os.urandom(22) |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
94 admin_username = input("Admin username (admin): ") or 'admin' |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
95 admin_password = getpass.getpass("Admin password: ") |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
96 if not admin_password: |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
97 logger.warning("No administration password set!") |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
98 logger.warning("Don't make this instance of FoodTruck public.") |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
99 logger.info("You can later set an admin password by editing " |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
100 "the `foodtruck.yml` file and using the " |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
101 "`chef admin genpass` command.") |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
102 else: |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
103 binpw = admin_password.encode('utf8') |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
104 hashpw = bcrypt.hashpw(binpw, bcrypt.gensalt()).decode('utf8') |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
105 admin_password = hashpw |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
106 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
107 ft_config = """ |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
108 security: |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
109 username: %(username)s |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
110 # You can generate another hashed password with `chef admin genpass`. |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
111 password: %(password)s |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
112 """ |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
113 ft_config = ft_config % { |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
114 'username': admin_username, |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
115 'password': admin_password |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
116 } |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
117 with open('foodtruck.yml', 'w', encoding='utf8') as fp: |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
118 fp.write(ft_config) |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
119 |
597
79a31a3c947b
admin: Better production config for FoodTruck, provide proper first site.
Ludovic Chabant <ludovic@chabant.com>
parents:
588
diff
changeset
|
120 flask_config = """ |
601
effbc78b5528
admin: Better error reporting, general clean-up.
Ludovic Chabant <ludovic@chabant.com>
parents:
597
diff
changeset
|
121 SECRET_KEY = %(secret_key)s |
597
79a31a3c947b
admin: Better production config for FoodTruck, provide proper first site.
Ludovic Chabant <ludovic@chabant.com>
parents:
588
diff
changeset
|
122 """ |
79a31a3c947b
admin: Better production config for FoodTruck, provide proper first site.
Ludovic Chabant <ludovic@chabant.com>
parents:
588
diff
changeset
|
123 flask_config = flask_config % {'secret_key': secret_key} |
79a31a3c947b
admin: Better production config for FoodTruck, provide proper first site.
Ludovic Chabant <ludovic@chabant.com>
parents:
588
diff
changeset
|
124 with open('app.cfg', 'w', encoding='utf8') as fp: |
79a31a3c947b
admin: Better production config for FoodTruck, provide proper first site.
Ludovic Chabant <ludovic@chabant.com>
parents:
588
diff
changeset
|
125 fp.write(flask_config) |
79a31a3c947b
admin: Better production config for FoodTruck, provide proper first site.
Ludovic Chabant <ludovic@chabant.com>
parents:
588
diff
changeset
|
126 |
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
127 def _generatePassword(self, ctx): |
640
59968ee07a07
admin: Don't require `bcrypt` for running FoodTruck with `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents:
619
diff
changeset
|
128 from foodtruck import bcryptfallback as bcrypt |
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
129 binpw = ctx.args.password.encode('utf8') |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
130 hashpw = bcrypt.hashpw(binpw, bcrypt.gensalt()).decode('utf8') |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
131 logger.info(hashpw) |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
132 |