##// END OF EJS Templates
marcink -
r1662:f62a960b merge beta
parent child Browse files
Show More
@@ -1,252 +1,258 b''
1 1 ################################################################################
2 2 ################################################################################
3 3 # RhodeCode - Pylons environment configuration #
4 4 # #
5 5 # The %(here)s variable will be replaced with the parent directory of this file#
6 6 ################################################################################
7 7
8 8 [DEFAULT]
9 9 debug = true
10 10 pdebug = false
11 11 ################################################################################
12 12 ## Uncomment and replace with the address which should receive ##
13 13 ## any error reports after application crash ##
14 14 ## Additionally those settings will be used by RhodeCode mailing system ##
15 15 ################################################################################
16 16 #email_to = admin@localhost
17 17 #error_email_from = paste_error@localhost
18 18 #app_email_from = rhodecode-noreply@localhost
19 19 #error_message =
20 20
21 21 #smtp_server = mail.server.com
22 22 #smtp_username =
23 23 #smtp_password =
24 24 #smtp_port =
25 25 #smtp_use_tls = false
26 26 #smtp_use_ssl = true
27 27 # Specify available auth parameters here (e.g. LOGIN PLAIN CRAM-MD5, etc.)
28 28 #smtp_auth =
29 29
30 30 [server:main]
31 31 ##nr of threads to spawn
32 32 threadpool_workers = 5
33 33
34 34 ##max request before thread respawn
35 35 threadpool_max_requests = 6
36 36
37 37 ##option to use threads of process
38 38 use_threadpool = true
39 39
40 40 use = egg:Paste#http
41 41 host = 0.0.0.0
42 42 port = 5000
43 43
44 44 [app:main]
45 45 use = egg:rhodecode
46 46 full_stack = true
47 47 static_files = true
48 48 lang=en
49 49 cache_dir = %(here)s/data
50 50 index_dir = %(here)s/data/index
51 51 app_instance_uuid = develop
52 52 cut_off_limit = 256000
53 53 force_https = false
54 54 commit_parse_limit = 25
55 55 use_gravatar = true
56 56 container_auth_enabled = false
57 57 proxypass_auth_enabled = false
58 58
59 59 ## overwrite schema of clone url
60 60 # available vars:
61 61 # scheme - http/https
62 62 # user - current user
63 63 # pass - password
64 64 # netloc - network location
65 65 # path - usually repo_name
66 66 # clone_uri = {scheme}://{user}{pass}{netloc}{path}
67 67
68 68 ####################################
69 69 ### CELERY CONFIG ####
70 70 ####################################
71 71 use_celery = false
72 72 broker.host = localhost
73 73 broker.vhost = rabbitmqhost
74 74 broker.port = 5672
75 75 broker.user = rabbitmq
76 76 broker.password = qweqwe
77 77
78 78 celery.imports = rhodecode.lib.celerylib.tasks
79 79
80 80 celery.result.backend = amqp
81 81 celery.result.dburi = amqp://
82 82 celery.result.serialier = json
83 83
84 84 #celery.send.task.error.emails = true
85 85 #celery.amqp.task.result.expires = 18000
86 86
87 87 celeryd.concurrency = 2
88 88 #celeryd.log.file = celeryd.log
89 89 celeryd.log.level = debug
90 90 celeryd.max.tasks.per.child = 1
91 91
92 92 #tasks will never be sent to the queue, but executed locally instead.
93 93 celery.always.eager = false
94 94
95 95 ####################################
96 96 ### BEAKER CACHE ####
97 97 ####################################
98 98 beaker.cache.data_dir=%(here)s/data/cache/data
99 99 beaker.cache.lock_dir=%(here)s/data/cache/lock
100 100
101 101 beaker.cache.regions=super_short_term,short_term,long_term,sql_cache_short,sql_cache_med,sql_cache_long
102 102
103 103 beaker.cache.super_short_term.type=memory
104 104 beaker.cache.super_short_term.expire=10
105 105 beaker.cache.super_short_term.key_length = 256
106 106
107 107 beaker.cache.short_term.type=memory
108 108 beaker.cache.short_term.expire=60
109 109 beaker.cache.short_term.key_length = 256
110 110
111 111 beaker.cache.long_term.type=memory
112 112 beaker.cache.long_term.expire=36000
113 113 beaker.cache.long_term.key_length = 256
114 114
115 115 beaker.cache.sql_cache_short.type=memory
116 116 beaker.cache.sql_cache_short.expire=10
117 117 beaker.cache.sql_cache_short.key_length = 256
118 118
119 119 beaker.cache.sql_cache_med.type=memory
120 120 beaker.cache.sql_cache_med.expire=360
121 121 beaker.cache.sql_cache_med.key_length = 256
122 122
123 123 beaker.cache.sql_cache_long.type=file
124 124 beaker.cache.sql_cache_long.expire=3600
125 125 beaker.cache.sql_cache_long.key_length = 256
126 126
127 127 ####################################
128 128 ### BEAKER SESSION ####
129 129 ####################################
130 130 ## Type of storage used for the session, current types are
131 131 ## dbm, file, memcached, database, and memory.
132 132 ## The storage uses the Container API
133 133 ##that is also used by the cache system.
134
135 #db session example
136 #beaker.session.type = ext:database
137 #beaker.session.sa.url = postgresql://postgres:qwe@localhost/rhodecode
138 #beaker.session.table_name = db_session
139
134 140 beaker.session.type = file
135 141
136 142 beaker.session.key = rhodecode
137 143 beaker.session.secret = g654dcno0-9873jhgfreyu
138 144 beaker.session.timeout = 36000
139 145
140 146 ##auto save the session to not to use .save()
141 147 beaker.session.auto = False
142 148
143 149 ##true exire at browser close
144 150 #beaker.session.cookie_expires = 3600
145 151
146 152
147 153 ################################################################################
148 154 ## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* ##
149 155 ## Debug mode will enable the interactive debugging tool, allowing ANYONE to ##
150 156 ## execute malicious code after an exception is raised. ##
151 157 ################################################################################
152 158 #set debug = false
153 159
154 160 ##################################
155 161 ### LOGVIEW CONFIG ###
156 162 ##################################
157 163 logview.sqlalchemy = #faa
158 164 logview.pylons.templating = #bfb
159 165 logview.pylons.util = #eee
160 166
161 167 #########################################################
162 168 ### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG ###
163 169 #########################################################
164 170 #sqlalchemy.db1.url = sqlite:///%(here)s/rhodecode.db
165 171 sqlalchemy.db1.url = postgresql://postgres:qwe@localhost/rhodecode
166 172 sqlalchemy.db1.echo = false
167 173 sqlalchemy.db1.pool_recycle = 3600
168 174 sqlalchemy.convert_unicode = true
169 175
170 176 ################################
171 177 ### LOGGING CONFIGURATION ####
172 178 ################################
173 179 [loggers]
174 180 keys = root, routes, rhodecode, sqlalchemy, beaker, templates
175 181
176 182 [handlers]
177 183 keys = console, console_sql
178 184
179 185 [formatters]
180 186 keys = generic, color_formatter, color_formatter_sql
181 187
182 188 #############
183 189 ## LOGGERS ##
184 190 #############
185 191 [logger_root]
186 192 level = NOTSET
187 193 handlers = console
188 194
189 195 [logger_routes]
190 196 level = DEBUG
191 197 handlers =
192 198 qualname = routes.middleware
193 199 # "level = DEBUG" logs the route matched and routing variables.
194 200 propagate = 1
195 201
196 202 [logger_beaker]
197 203 level = DEBUG
198 204 handlers =
199 205 qualname = beaker.container
200 206 propagate = 1
201 207
202 208 [logger_templates]
203 209 level = INFO
204 210 handlers =
205 211 qualname = pylons.templating
206 212 propagate = 1
207 213
208 214 [logger_rhodecode]
209 215 level = DEBUG
210 216 handlers =
211 217 qualname = rhodecode
212 218 propagate = 1
213 219
214 220 [logger_sqlalchemy]
215 221 level = INFO
216 222 handlers = console_sql
217 223 qualname = sqlalchemy.engine
218 224 propagate = 0
219 225
220 226 ##############
221 227 ## HANDLERS ##
222 228 ##############
223 229
224 230 [handler_console]
225 231 class = StreamHandler
226 232 args = (sys.stderr,)
227 233 level = DEBUG
228 234 formatter = color_formatter
229 235
230 236 [handler_console_sql]
231 237 class = StreamHandler
232 238 args = (sys.stderr,)
233 239 level = DEBUG
234 240 formatter = color_formatter_sql
235 241
236 242 ################
237 243 ## FORMATTERS ##
238 244 ################
239 245
240 246 [formatter_generic]
241 247 format = %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
242 248 datefmt = %Y-%m-%d %H:%M:%S
243 249
244 250 [formatter_color_formatter]
245 251 class=rhodecode.lib.colored_formatter.ColorFormatter
246 252 format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
247 253 datefmt = %Y-%m-%d %H:%M:%S
248 254
249 255 [formatter_color_formatter_sql]
250 256 class=rhodecode.lib.colored_formatter.ColorFormatterSql
251 257 format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
252 258 datefmt = %Y-%m-%d %H:%M:%S
@@ -1,251 +1,257 b''
1 1 ################################################################################
2 2 ################################################################################
3 3 # RhodeCode - Pylons environment configuration #
4 4 # #
5 5 # The %(here)s variable will be replaced with the parent directory of this file#
6 6 ################################################################################
7 7
8 8 [DEFAULT]
9 9 debug = true
10 10 pdebug = false
11 11 ################################################################################
12 12 ## Uncomment and replace with the address which should receive ##
13 13 ## any error reports after application crash ##
14 14 ## Additionally those settings will be used by RhodeCode mailing system ##
15 15 ################################################################################
16 16 #email_to = admin@localhost
17 17 #error_email_from = paste_error@localhost
18 18 #app_email_from = rhodecode-noreply@localhost
19 19 #error_message =
20 20
21 21 #smtp_server = mail.server.com
22 22 #smtp_username =
23 23 #smtp_password =
24 24 #smtp_port =
25 25 #smtp_use_tls = false
26 26 #smtp_use_ssl = true
27 27 # Specify available auth parameters here (e.g. LOGIN PLAIN CRAM-MD5, etc.)
28 28 #smtp_auth =
29 29
30 30 [server:main]
31 31 ##nr of threads to spawn
32 32 threadpool_workers = 5
33 33
34 34 ##max request before thread respawn
35 35 threadpool_max_requests = 10
36 36
37 37 ##option to use threads of process
38 38 use_threadpool = true
39 39
40 40 use = egg:Paste#http
41 41 host = 127.0.0.1
42 42 port = 8001
43 43
44 44 [app:main]
45 45 use = egg:rhodecode
46 46 full_stack = true
47 47 static_files = true
48 48 lang=en
49 49 cache_dir = %(here)s/data
50 50 index_dir = %(here)s/data/index
51 51 app_instance_uuid = prod1234
52 52 cut_off_limit = 256000
53 53 force_https = false
54 54 commit_parse_limit = 50
55 55 use_gravatar = true
56 56 container_auth_enabled = false
57 57 proxypass_auth_enabled = false
58 58
59 59 ## available vars
60 60 ## scheme - http/https
61 61 ## user - current user
62 62 ## pass - password
63 63 ## netloc - network location
64 64 ## path - usually repo_name
65 65 clone_uri = {scheme}://{user}{pass}{netloc}{path}
66 66
67 67 ####################################
68 68 ### CELERY CONFIG ####
69 69 ####################################
70 70 use_celery = false
71 71 broker.host = localhost
72 72 broker.vhost = rabbitmqhost
73 73 broker.port = 5672
74 74 broker.user = rabbitmq
75 75 broker.password = qweqwe
76 76
77 77 celery.imports = rhodecode.lib.celerylib.tasks
78 78
79 79 celery.result.backend = amqp
80 80 celery.result.dburi = amqp://
81 81 celery.result.serialier = json
82 82
83 83 #celery.send.task.error.emails = true
84 84 #celery.amqp.task.result.expires = 18000
85 85
86 86 celeryd.concurrency = 2
87 87 #celeryd.log.file = celeryd.log
88 88 celeryd.log.level = debug
89 89 celeryd.max.tasks.per.child = 1
90 90
91 91 #tasks will never be sent to the queue, but executed locally instead.
92 92 celery.always.eager = false
93 93
94 94 ####################################
95 95 ### BEAKER CACHE ####
96 96 ####################################
97 97 beaker.cache.data_dir=%(here)s/data/cache/data
98 98 beaker.cache.lock_dir=%(here)s/data/cache/lock
99 99
100 100 beaker.cache.regions=super_short_term,short_term,long_term,sql_cache_short,sql_cache_med,sql_cache_long
101 101
102 102 beaker.cache.super_short_term.type=memory
103 103 beaker.cache.super_short_term.expire=10
104 104 beaker.cache.super_short_term.key_length = 256
105 105
106 106 beaker.cache.short_term.type=memory
107 107 beaker.cache.short_term.expire=60
108 108 beaker.cache.short_term.key_length = 256
109 109
110 110 beaker.cache.long_term.type=memory
111 111 beaker.cache.long_term.expire=36000
112 112 beaker.cache.long_term.key_length = 256
113 113
114 114 beaker.cache.sql_cache_short.type=memory
115 115 beaker.cache.sql_cache_short.expire=10
116 116 beaker.cache.sql_cache_short.key_length = 256
117 117
118 118 beaker.cache.sql_cache_med.type=memory
119 119 beaker.cache.sql_cache_med.expire=360
120 120 beaker.cache.sql_cache_med.key_length = 256
121 121
122 122 beaker.cache.sql_cache_long.type=file
123 123 beaker.cache.sql_cache_long.expire=3600
124 124 beaker.cache.sql_cache_long.key_length = 256
125 125
126 126 ####################################
127 127 ### BEAKER SESSION ####
128 128 ####################################
129 129 ## Type of storage used for the session, current types are
130 130 ## dbm, file, memcached, database, and memory.
131 131 ## The storage uses the Container API
132 132 ##that is also used by the cache system.
133
134 #db session example
135 #beaker.session.type = ext:database
136 #beaker.session.sa.url = postgresql://postgres:qwe@localhost/rhodecode
137 #beaker.session.table_name = db_session
138
133 139 beaker.session.type = file
134 140
135 141 beaker.session.key = rhodecode
136 142 beaker.session.secret = g654dcno0-9873jhgfreyu
137 143 beaker.session.timeout = 36000
138 144
139 145 ##auto save the session to not to use .save()
140 146 beaker.session.auto = False
141 147
142 148 ##true exire at browser close
143 149 #beaker.session.cookie_expires = 3600
144 150
145 151
146 152 ################################################################################
147 153 ## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* ##
148 154 ## Debug mode will enable the interactive debugging tool, allowing ANYONE to ##
149 155 ## execute malicious code after an exception is raised. ##
150 156 ################################################################################
151 157 set debug = false
152 158
153 159 ##################################
154 160 ### LOGVIEW CONFIG ###
155 161 ##################################
156 162 logview.sqlalchemy = #faa
157 163 logview.pylons.templating = #bfb
158 164 logview.pylons.util = #eee
159 165
160 166 #########################################################
161 167 ### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG ###
162 168 #########################################################
163 169 #sqlalchemy.db1.url = sqlite:///%(here)s/rhodecode.db
164 170 sqlalchemy.db1.url = postgresql://postgres:qwe@localhost/rhodecode
165 171 sqlalchemy.db1.echo = false
166 172 sqlalchemy.db1.pool_recycle = 3600
167 173 sqlalchemy.convert_unicode = true
168 174
169 175 ################################
170 176 ### LOGGING CONFIGURATION ####
171 177 ################################
172 178 [loggers]
173 179 keys = root, routes, rhodecode, sqlalchemy, beaker, templates
174 180
175 181 [handlers]
176 182 keys = console, console_sql
177 183
178 184 [formatters]
179 185 keys = generic, color_formatter, color_formatter_sql
180 186
181 187 #############
182 188 ## LOGGERS ##
183 189 #############
184 190 [logger_root]
185 191 level = NOTSET
186 192 handlers = console
187 193
188 194 [logger_routes]
189 195 level = DEBUG
190 196 handlers =
191 197 qualname = routes.middleware
192 198 # "level = DEBUG" logs the route matched and routing variables.
193 199 propagate = 1
194 200
195 201 [logger_beaker]
196 202 level = DEBUG
197 203 handlers =
198 204 qualname = beaker.container
199 205 propagate = 1
200 206
201 207 [logger_templates]
202 208 level = INFO
203 209 handlers =
204 210 qualname = pylons.templating
205 211 propagate = 1
206 212
207 213 [logger_rhodecode]
208 214 level = DEBUG
209 215 handlers =
210 216 qualname = rhodecode
211 217 propagate = 1
212 218
213 219 [logger_sqlalchemy]
214 220 level = INFO
215 221 handlers = console_sql
216 222 qualname = sqlalchemy.engine
217 223 propagate = 0
218 224
219 225 ##############
220 226 ## HANDLERS ##
221 227 ##############
222 228
223 229 [handler_console]
224 230 class = StreamHandler
225 231 args = (sys.stderr,)
226 232 level = INFO
227 233 formatter = generic
228 234
229 235 [handler_console_sql]
230 236 class = StreamHandler
231 237 args = (sys.stderr,)
232 238 level = WARN
233 239 formatter = generic
234 240
235 241 ################
236 242 ## FORMATTERS ##
237 243 ################
238 244
239 245 [formatter_generic]
240 246 format = %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
241 247 datefmt = %Y-%m-%d %H:%M:%S
242 248
243 249 [formatter_color_formatter]
244 250 class=rhodecode.lib.colored_formatter.ColorFormatter
245 251 format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
246 252 datefmt = %Y-%m-%d %H:%M:%S
247 253
248 254 [formatter_color_formatter_sql]
249 255 class=rhodecode.lib.colored_formatter.ColorFormatterSql
250 256 format= %(asctime)s.%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
251 257 datefmt = %Y-%m-%d %H:%M:%S No newline at end of file
@@ -1,242 +1,248 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 rhodecode.controllers.api
4 4 ~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 6 JSON RPC controller
7 7
8 8 :created_on: Aug 20, 2011
9 9 :author: marcink
10 10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
11 11 :license: GPLv3, see COPYING for more details.
12 12 """
13 13 # This program is free software; you can redistribute it and/or
14 14 # modify it under the terms of the GNU General Public License
15 15 # as published by the Free Software Foundation; version 2
16 16 # of the License or (at your opinion) any later version of the license.
17 17 #
18 18 # This program is distributed in the hope that it will be useful,
19 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 21 # GNU General Public License for more details.
22 22 #
23 23 # You should have received a copy of the GNU General Public License
24 24 # along with this program; if not, write to the Free Software
25 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 26 # MA 02110-1301, USA.
27 27
28 28 import inspect
29 29 import logging
30 30 import types
31 31 import urllib
32 32 import traceback
33 33
34 34 from rhodecode.lib.compat import izip_longest, json
35 35
36 36 from paste.response import replace_header
37 37
38 38 from pylons.controllers import WSGIController
39 from pylons.controllers.util import Response
39
40 40
41 41 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError, \
42 42 HTTPBadRequest, HTTPError
43 43
44 44 from rhodecode.model.db import User
45 45 from rhodecode.lib.auth import AuthUser
46 46
47 47 log = logging.getLogger('JSONRPC')
48 48
49 49 class JSONRPCError(BaseException):
50 50
51 51 def __init__(self, message):
52 52 self.message = message
53 53
54 54 def __str__(self):
55 55 return str(self.message)
56 56
57 57
58 58 def jsonrpc_error(message, code=None):
59 """Generate a Response object with a JSON-RPC error body"""
60 return Response(body=json.dumps(dict(result=None,
61 error=message)))
59 """
60 Generate a Response object with a JSON-RPC error body
61 """
62 from pylons.controllers.util import Response
63 resp = Response(body=json.dumps(dict(result=None, error=message)),
64 status=code,
65 content_type='application/json')
66 return resp
67
62 68
63 69
64 70 class JSONRPCController(WSGIController):
65 71 """
66 72 A WSGI-speaking JSON-RPC controller class
67 73
68 74 See the specification:
69 75 <http://json-rpc.org/wiki/specification>`.
70 76
71 77 Valid controller return values should be json-serializable objects.
72 78
73 79 Sub-classes should catch their exceptions and raise JSONRPCError
74 80 if they want to pass meaningful errors to the client.
75 81
76 82 """
77 83
78 84 def _get_method_args(self):
79 85 """
80 86 Return `self._rpc_args` to dispatched controller method
81 87 chosen by __call__
82 88 """
83 89 return self._rpc_args
84 90
85 91 def __call__(self, environ, start_response):
86 92 """
87 93 Parse the request body as JSON, look up the method on the
88 94 controller and if it exists, dispatch to it.
89 95 """
90 96 if 'CONTENT_LENGTH' not in environ:
91 97 log.debug("No Content-Length")
92 98 return jsonrpc_error(message="No Content-Length in request")
93 99 else:
94 100 length = environ['CONTENT_LENGTH'] or 0
95 101 length = int(environ['CONTENT_LENGTH'])
96 102 log.debug('Content-Length: %s', length)
97 103
98 104 if length == 0:
99 105 log.debug("Content-Length is 0")
100 106 return jsonrpc_error(message="Content-Length is 0")
101 107
102 108 raw_body = environ['wsgi.input'].read(length)
103 109
104 110 try:
105 111 json_body = json.loads(urllib.unquote_plus(raw_body))
106 112 except ValueError, e:
107 113 #catch JSON errors Here
108 114 return jsonrpc_error(message="JSON parse error ERR:%s RAW:%r" \
109 115 % (e, urllib.unquote_plus(raw_body)))
110 116
111 117 #check AUTH based on API KEY
112 118 try:
113 119 self._req_api_key = json_body['api_key']
114 120 self._req_method = json_body['method']
115 121 self._req_params = json_body['args']
116 122 log.debug('method: %s, params: %s',
117 123 self._req_method,
118 124 self._req_params)
119 125 except KeyError, e:
120 126 return jsonrpc_error(message='Incorrect JSON query missing %s' % e)
121 127
122 128 #check if we can find this session using api_key
123 129 try:
124 130 u = User.get_by_api_key(self._req_api_key)
125 131 auth_u = AuthUser(u.user_id, self._req_api_key)
126 132 except Exception, e:
127 133 return jsonrpc_error(message='Invalid API KEY')
128 134
129 135 self._error = None
130 136 try:
131 137 self._func = self._find_method()
132 138 except AttributeError, e:
133 139 return jsonrpc_error(message=str(e))
134 140
135 141 # now that we have a method, add self._req_params to
136 142 # self.kargs and dispatch control to WGIController
137 143 argspec = inspect.getargspec(self._func)
138 144 arglist = argspec[0][1:]
139 145 defaults = argspec[3] or []
140 146 default_empty = types.NotImplementedType
141 147
142 148 kwarglist = list(izip_longest(reversed(arglist), reversed(defaults),
143 149 fillvalue=default_empty))
144 150
145 151 # this is little trick to inject logged in user for
146 152 # perms decorators to work they expect the controller class to have
147 153 # rhodecode_user attribute set
148 154 self.rhodecode_user = auth_u
149 155
150 156 # This attribute will need to be first param of a method that uses
151 157 # api_key, which is translated to instance of user at that name
152 158 USER_SESSION_ATTR = 'apiuser'
153 159
154 160 if USER_SESSION_ATTR not in arglist:
155 161 return jsonrpc_error(message='This method [%s] does not support '
156 162 'authentication (missing %s param)' %
157 163 (self._func.__name__, USER_SESSION_ATTR))
158 164
159 165 # get our arglist and check if we provided them as args
160 166 for arg, default in kwarglist:
161 167 if arg == USER_SESSION_ATTR:
162 168 # USER_SESSION_ATTR is something translated from api key and
163 169 # this is checked before so we don't need validate it
164 170 continue
165 171
166 172 # skip the required param check if it's default value is
167 173 # NotImplementedType (default_empty)
168 174 if not self._req_params or (type(default) == default_empty
169 175 and arg not in self._req_params):
170 176 return jsonrpc_error(message=('Missing non optional %s arg '
171 177 'in JSON DATA') % arg)
172 178
173 179 self._rpc_args = {USER_SESSION_ATTR:u}
174 180 self._rpc_args.update(self._req_params)
175 181
176 182 self._rpc_args['action'] = self._req_method
177 183 self._rpc_args['environ'] = environ
178 184 self._rpc_args['start_response'] = start_response
179 185
180 186 status = []
181 187 headers = []
182 188 exc_info = []
183 189 def change_content(new_status, new_headers, new_exc_info=None):
184 190 status.append(new_status)
185 191 headers.extend(new_headers)
186 192 exc_info.append(new_exc_info)
187 193
188 194 output = WSGIController.__call__(self, environ, change_content)
189 195 output = list(output)
190 196 headers.append(('Content-Length', str(len(output[0]))))
191 197 replace_header(headers, 'Content-Type', 'application/json')
192 198 start_response(status[0], headers, exc_info[0])
193 199
194 200 return output
195 201
196 202 def _dispatch_call(self):
197 203 """
198 204 Implement dispatch interface specified by WSGIController
199 205 """
200 206 try:
201 207 raw_response = self._inspect_call(self._func)
202 208 if isinstance(raw_response, HTTPError):
203 209 self._error = str(raw_response)
204 210 except JSONRPCError, e:
205 211 self._error = str(e)
206 212 except Exception, e:
207 213 log.error('Encountered unhandled exception: %s' \
208 214 % traceback.format_exc())
209 215 json_exc = JSONRPCError('Internal server error')
210 216 self._error = str(json_exc)
211 217
212 218 if self._error is not None:
213 219 raw_response = None
214 220
215 221 response = dict(result=raw_response, error=self._error)
216 222
217 223 try:
218 224 return json.dumps(response)
219 225 except TypeError, e:
220 226 log.debug('Error encoding response: %s', e)
221 227 return json.dumps(dict(result=None,
222 228 error="Error encoding response"))
223 229
224 230 def _find_method(self):
225 231 """
226 232 Return method named by `self._req_method` in controller if able
227 233 """
228 234 log.debug('Trying to find JSON-RPC method: %s', self._req_method)
229 235 if self._req_method.startswith('_'):
230 236 raise AttributeError("Method not allowed")
231 237
232 238 try:
233 239 func = getattr(self, self._req_method, None)
234 240 except UnicodeEncodeError:
235 241 raise AttributeError("Problem decoding unicode in requested "
236 242 "method name.")
237 243
238 244 if isinstance(func, types.MethodType):
239 245 return func
240 246 else:
241 247 raise AttributeError("No such method: %s" % self._req_method)
242 248
General Comments 0
You need to be logged in to leave comments. Login now