Mercurial > piecrust2
annotate piecrust/commands/builtin/admin.py @ 842:a85d08ffe1f6
admin: Fix crash when running `admin run` outside of a website.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 19 Feb 2017 22:04:33 -0800 |
parents | 5e91bc0e3b4d |
children | 4850f8c21b6e |
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 |
842
a85d08ffe1f6
admin: Fix crash when running `admin run` outside of a website.
Ludovic Chabant <ludovic@chabant.com>
parents:
778
diff
changeset
|
6 from piecrust.pathutil import SiteNotFoundError |
588
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 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 logger = logging.getLogger(__name__) |
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 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 class AdministrationPanelCommand(ChefCommand): |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 def __init__(self): |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 super(AdministrationPanelCommand, self).__init__() |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 self.name = 'admin' |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 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
|
17 self.requires_website = False |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 def setupParser(self, parser, app): |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 subparsers = parser.add_subparsers() |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 p = subparsers.add_parser( |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 'init', |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 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
|
25 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
|
26 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 p = subparsers.add_parser( |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 'genpass', |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 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
|
30 "admin password")) |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 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
|
32 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
|
33 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 p = subparsers.add_parser( |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 'run', |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 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
|
37 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
|
38 '-p', '--port', |
200c7063affa
admin: Change the default admin server port to 8090, add `--port` option.
Ludovic Chabant <ludovic@chabant.com>
parents:
611
diff
changeset
|
39 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
|
40 default=8090) |
200c7063affa
admin: Change the default admin server port to 8090, add `--port` option.
Ludovic Chabant <ludovic@chabant.com>
parents:
611
diff
changeset
|
41 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
|
42 '-a', '--address', |
200c7063affa
admin: Change the default admin server port to 8090, add `--port` option.
Ludovic Chabant <ludovic@chabant.com>
parents:
611
diff
changeset
|
43 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
|
44 default='localhost') |
656
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
45 p.add_argument( |
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
46 '--no-assets', |
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
47 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
|
48 dest='monitor_assets', |
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
49 action='store_false') |
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
50 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
|
51 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
52 def checkedRun(self, ctx): |
762
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
53 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
|
54 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
|
55 |
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
56 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
|
57 ctx.parser.parse_args(['admin', '--help']) |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
58 return |
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
59 return ctx.args.sub_func(ctx) |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
60 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
61 def _runFoodTruck(self, ctx): |
656
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
62 # 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
|
63 # of this check. |
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
64 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
|
65 not ctx.args.debug or |
dba53f0f7671
admin: run an asset processing loop in the background.
Ludovic Chabant <ludovic@chabant.com>
parents:
653
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 appfactory = PieCrustFactory( |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
70 ctx.app.root_dir, |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
71 cache=ctx.app.cache.enabled, |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
72 cache_key=ctx.app.cache_key, |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
73 config_variant=ctx.config_variant, |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
74 config_values=ctx.config_values, |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
75 debug=ctx.app.debug, |
c84647485ab2
admin: Fix crash when running the `admin` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
656
diff
changeset
|
76 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
|
77 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
|
78 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
|
79 proc_loop.start() |
653
466bbddd121e
admin: Run the asset pipeline before showing the admin panel.
Ludovic Chabant <ludovic@chabant.com>
parents:
640
diff
changeset
|
80 |
778
5e91bc0e3b4d
internal: Move admin panel code into the piecrust package.
Ludovic Chabant <ludovic@chabant.com>
parents:
762
diff
changeset
|
81 es = { |
5e91bc0e3b4d
internal: Move admin panel code into the piecrust package.
Ludovic Chabant <ludovic@chabant.com>
parents:
762
diff
changeset
|
82 'FOODTRUCK_CMDLINE_MODE': True, |
5e91bc0e3b4d
internal: Move admin panel code into the piecrust package.
Ludovic Chabant <ludovic@chabant.com>
parents:
762
diff
changeset
|
83 'FOODTRUCK_ROOT': ctx.app.root_dir} |
5e91bc0e3b4d
internal: Move admin panel code into the piecrust package.
Ludovic Chabant <ludovic@chabant.com>
parents:
762
diff
changeset
|
84 from piecrust.admin.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
|
85 run_foodtruck( |
200c7063affa
admin: Change the default admin server port to 8090, add `--port` option.
Ludovic Chabant <ludovic@chabant.com>
parents:
611
diff
changeset
|
86 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
|
87 port=ctx.args.port, |
778
5e91bc0e3b4d
internal: Move admin panel code into the piecrust package.
Ludovic Chabant <ludovic@chabant.com>
parents:
762
diff
changeset
|
88 debug=ctx.args.debug, |
5e91bc0e3b4d
internal: Move admin panel code into the piecrust package.
Ludovic Chabant <ludovic@chabant.com>
parents:
762
diff
changeset
|
89 extra_settings=es) |
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
90 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
91 def _initFoodTruck(self, ctx): |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
92 import getpass |
778
5e91bc0e3b4d
internal: Move admin panel code into the piecrust package.
Ludovic Chabant <ludovic@chabant.com>
parents:
762
diff
changeset
|
93 from piecrust.admin import bcryptfallback as bcrypt |
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
94 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
95 secret_key = os.urandom(22) |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
96 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
|
97 admin_password = getpass.getpass("Admin password: ") |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
98 if not admin_password: |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
99 logger.warning("No administration password set!") |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
100 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
|
101 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
|
102 "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
|
103 "`chef admin genpass` command.") |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
104 else: |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
105 binpw = admin_password.encode('utf8') |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
106 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
|
107 admin_password = hashpw |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
108 |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
109 ft_config = """ |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
110 security: |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
111 username: %(username)s |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
112 # 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
|
113 password: %(password)s |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
114 """ |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
115 ft_config = ft_config % { |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
116 'username': admin_username, |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
117 'password': admin_password |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
118 } |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
119 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
|
120 fp.write(ft_config) |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
121 |
597
79a31a3c947b
admin: Better production config for FoodTruck, provide proper first site.
Ludovic Chabant <ludovic@chabant.com>
parents:
588
diff
changeset
|
122 flask_config = """ |
601
effbc78b5528
admin: Better error reporting, general clean-up.
Ludovic Chabant <ludovic@chabant.com>
parents:
597
diff
changeset
|
123 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
|
124 """ |
79a31a3c947b
admin: Better production config for FoodTruck, provide proper first site.
Ludovic Chabant <ludovic@chabant.com>
parents:
588
diff
changeset
|
125 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
|
126 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
|
127 fp.write(flask_config) |
79a31a3c947b
admin: Better production config for FoodTruck, provide proper first site.
Ludovic Chabant <ludovic@chabant.com>
parents:
588
diff
changeset
|
128 |
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
129 def _generatePassword(self, ctx): |
778
5e91bc0e3b4d
internal: Move admin panel code into the piecrust package.
Ludovic Chabant <ludovic@chabant.com>
parents:
762
diff
changeset
|
130 from piecrust.admin import bcryptfallback as bcrypt |
588
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
131 binpw = ctx.args.password.encode('utf8') |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
132 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
|
133 logger.info(hashpw) |
b884bef3e611
admin: New `admin` command to manage FoodTruck-related things.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
134 |