1 # copyright 2003-2010 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 """google appengine configuration |
|
19 |
|
20 """ |
|
21 __docformat__ = "restructuredtext en" |
|
22 |
|
23 import os |
|
24 from os.path import join |
|
25 |
|
26 from cubicweb import CW_SOFTWARE_ROOT |
|
27 from cubicweb.cwconfig import CubicWebConfiguration |
|
28 from cubicweb.web.webconfig import WebConfiguration, merge_options |
|
29 from cubicweb.server.serverconfig import ServerConfiguration |
|
30 from cubicweb.goa.dbmyams import load_schema |
|
31 |
|
32 UNSUPPORTED_OPTIONS = set(('connections-pool-size', |
|
33 'pyro-host', 'pyro-instance-id', |
|
34 'pyro-ns-host', 'pyro-ns-group', |
|
35 'https-url', 'host', 'pid-file', 'uid', 'base-url', 'log-file', |
|
36 'smtp-host', 'smtp-port', |
|
37 'embed-allowed', |
|
38 )) |
|
39 |
|
40 # XXX fix: |
|
41 # * default sender-name / sender-addr value |
|
42 # * what about *session-time |
|
43 # * check auth-mode=http + fix doc (eg require use-google-auth = False) |
|
44 |
|
45 class GAEConfiguration(ServerConfiguration, WebConfiguration): |
|
46 """repository and web instance in Google AppEngine environment""" |
|
47 name = 'app' |
|
48 repo_method = 'inmemory' |
|
49 options = merge_options(( |
|
50 ('included-cubes', |
|
51 {'type' : 'csv', |
|
52 'default': [], |
|
53 'help': 'list of db model based cubes used by the instance.', |
|
54 'group': 'main', 'level': 1, |
|
55 }), |
|
56 ('included-yams-cubes', |
|
57 {'type' : 'csv', |
|
58 'default': [], |
|
59 'help': 'list of yams based cubes used by the instance.', |
|
60 'group': 'main', 'level': 1, |
|
61 }), |
|
62 ('use-google-auth', |
|
63 {'type' : 'yn', |
|
64 'default': True, |
|
65 'help': 'does this instance rely on google authentication service or not.', |
|
66 'group': 'main', 'level': 1, |
|
67 }), |
|
68 ('schema-type', |
|
69 {'type' : 'choice', 'choices': ('yams', 'dbmodel'), |
|
70 'default': 'yams', |
|
71 'help': 'does this instance is defining its schema using yams or db model.', |
|
72 'group': 'main', 'level': 1, |
|
73 }), |
|
74 # overriden options |
|
75 ('query-log-file', |
|
76 {'type' : 'string', |
|
77 'default': None, |
|
78 'help': 'web instance query log file: DON\'T SET A VALUE HERE WHEN ' |
|
79 'UPLOADING YOUR INSTANCE. This should only be used to analyse ' |
|
80 'queries issued by your instance in the development environment.', |
|
81 'group': 'main', 'level': 2, |
|
82 }), |
|
83 ('anonymous-user', |
|
84 {'type' : 'string', |
|
85 'default': None, |
|
86 'help': 'login of the CubicWeb user account to use for anonymous user ' |
|
87 '(if you want to allow anonymous). This option will be ignored if ' |
|
88 'use-google-auth option is set (in which case you should control ' |
|
89 'anonymous access using the app.yaml file)', |
|
90 'group': 'main', 'level': 1, |
|
91 }), |
|
92 |
|
93 ) + WebConfiguration.options + ServerConfiguration.options) |
|
94 options = [(optname, optdict) for optname, optdict in options |
|
95 if not optname in UNSUPPORTED_OPTIONS] |
|
96 |
|
97 cubicweb_appobject_path = WebConfiguration.cubicweb_appobject_path | ServerConfiguration.cubicweb_appobject_path |
|
98 cubicweb_appobject_path = list(cubicweb_appobject_path) + ['goa/appobjects'] |
|
99 cube_appobject_path = WebConfiguration.cube_appobject_path | ServerConfiguration.cube_appobject_path |
|
100 |
|
101 # use file system schema |
|
102 read_instance_schema = False |
|
103 # schema is not persistent, don't load schema hooks (unavailable) |
|
104 schema_hooks = False |
|
105 # no user workflow for now |
|
106 consider_user_state = False |
|
107 |
|
108 # deactivate some hooks during [pre|post]create scripts execution |
|
109 # (unique values check, owned_by/created_by relations setup) |
|
110 free_wheel = True |
|
111 |
|
112 if not os.environ.get('APYCOT_ROOT'): |
|
113 CUBES_DIR = join(CW_SOFTWARE_ROOT, '../cubes') |
|
114 |
|
115 def __init__(self, appid, apphome=None): |
|
116 if apphome is None: |
|
117 apphome = 'data' |
|
118 self._apphome = apphome |
|
119 self._base_url = None |
|
120 CubicWebConfiguration.__init__(self, appid) |
|
121 |
|
122 def __getitem__(self, key): |
|
123 if key == 'connections-pool-size': |
|
124 return 4 # > 1 to allow multiple user sessions in tests |
|
125 if key == 'base-url': |
|
126 return self._base_url |
|
127 return super(GAEConfiguration, self).__getitem__(key) |
|
128 |
|
129 # overriden from cubicweb base configuration |
|
130 |
|
131 @property |
|
132 def apphome(self): |
|
133 return self._apphome |
|
134 |
|
135 def cubes(self): |
|
136 """return the list of top level cubes used by this instance (eg |
|
137 without dependencies) |
|
138 """ |
|
139 if self._cubes is None: |
|
140 cubes = self['included-cubes'] + self['included-yams-cubes'] |
|
141 cubes = self.expand_cubes(cubes) |
|
142 return self.reorder_cubes(cubes) |
|
143 return self._cubes |
|
144 |
|
145 def vc_config(self): |
|
146 """return CubicWeb's engine and instance's cube versions number""" |
|
147 return {} |
|
148 |
|
149 # overriden from cubicweb web configuration |
|
150 |
|
151 def instance_md5_version(self): |
|
152 return '' |
|
153 |
|
154 def _init_base_url(self): |
|
155 pass |
|
156 |
|
157 # overriden from cubicweb server configuration |
|
158 |
|
159 def sources(self): |
|
160 return {'system': {'adapter': 'gae'}} |
|
161 |
|
162 def load_schema(self, schemaclasses=None, extrahook=None): |
|
163 try: |
|
164 return self._schema |
|
165 except AttributeError: |
|
166 self._schema = load_schema(self, schemaclasses, extrahook) |
|
167 return self._schema |
|
168 |
|
169 # goa specific |
|
170 def repo_session(self, sessionid): |
|
171 return self.repository()._sessions[sessionid] |
|
172 |
|
173 def is_anonymous_user(self, login): |
|
174 if self['use-google-auth']: |
|
175 from google.appengine.api import users |
|
176 return users.get_current_user() is None |
|
177 else: |
|
178 return login == self.anonymous_user()[0] |
|
179 |
|