|
1 # copyright 2017 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
3 # |
|
4 # This file is part of CubicWeb. |
|
5 # |
|
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
7 # terms of the GNU Lesser General Public License as published by the Free |
|
8 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
9 # any later version. |
|
10 # |
|
11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
14 # details. |
|
15 # |
|
16 # You should have received a copy of the GNU Lesser General Public License along |
|
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
18 """Configuration for CubicWeb instances on top of a Pyramid application""" |
|
19 |
|
20 from os import path |
|
21 import random |
|
22 import string |
|
23 |
|
24 from logilab.common.configuration import merge_options |
|
25 |
|
26 from cubicweb.cwconfig import CONFIGURATIONS |
|
27 from cubicweb.server.serverconfig import ServerConfiguration |
|
28 from cubicweb.toolsutils import fill_templated_file |
|
29 from cubicweb.web.webconfig import BaseWebConfiguration |
|
30 |
|
31 |
|
32 def get_random_secret_key(): |
|
33 """Return 50-character secret string""" |
|
34 chars = string.ascii_letters + string.digits |
|
35 return "".join([random.choice(chars) for i in range(50)]) |
|
36 |
|
37 |
|
38 class CubicWebPyramidConfiguration(BaseWebConfiguration, ServerConfiguration): |
|
39 """Pyramid application with a CubicWeb repository""" |
|
40 name = 'pyramid' |
|
41 |
|
42 cubicweb_appobject_path = (BaseWebConfiguration.cubicweb_appobject_path |
|
43 | ServerConfiguration.cubicweb_appobject_path) |
|
44 cube_appobject_path = (BaseWebConfiguration.cube_appobject_path |
|
45 | ServerConfiguration.cube_appobject_path) |
|
46 |
|
47 options = merge_options(ServerConfiguration.options + |
|
48 BaseWebConfiguration.options) |
|
49 |
|
50 def write_development_ini(self, cubes): |
|
51 """Write a 'development.ini' file into apphome.""" |
|
52 template_fpath = path.join(path.dirname(__file__), 'development.ini.tmpl') |
|
53 target_fpath = path.join(self.apphome, 'development.ini') |
|
54 context = { |
|
55 'instance': self.appid, |
|
56 'cubename': cubes[0], |
|
57 'session-secret': get_random_secret_key(), |
|
58 'auth-authtkt-persistent-secret': get_random_secret_key(), |
|
59 'auth-authtkt-session-secret': get_random_secret_key(), |
|
60 } |
|
61 fill_templated_file(template_fpath, target_fpath, context) |
|
62 |
|
63 |
|
64 CONFIGURATIONS.append(CubicWebPyramidConfiguration) |