comparison rhodecode/controllers/api/__init__.py @ 1500:256e729a94cd beta

Extended API - updated docs - created two new methods for creating users and creating users groups - changed user attribute generated from api_key to apiuser for better name compatibility with functoin parameters
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 30 Sep 2011 18:03:20 +0300
parents b951731f2143
children ed3254ac279b
comparison
equal deleted inserted replaced
1499:182f5bd3b49d 1500:256e729a94cd
134 # self.kargs and dispatch control to WGIController 134 # self.kargs and dispatch control to WGIController
135 arglist = inspect.getargspec(self._func)[0][1:] 135 arglist = inspect.getargspec(self._func)[0][1:]
136 136
137 # this is little trick to inject logged in user for 137 # this is little trick to inject logged in user for
138 # perms decorators to work they expect the controller class to have 138 # perms decorators to work they expect the controller class to have
139 # rhodecode_user set 139 # rhodecode_user attribute set
140 self.rhodecode_user = auth_u 140 self.rhodecode_user = auth_u
141 141
142 if 'user' not in arglist: 142 # This attribute will need to be first param of a method that uses
143 # api_key, which is translated to instance of user at that name
144 USER_SESSION_ATTR = 'apiuser'
145
146 if USER_SESSION_ATTR not in arglist:
143 return jsonrpc_error(message='This method [%s] does not support ' 147 return jsonrpc_error(message='This method [%s] does not support '
144 'authentication (missing user param)' % 148 'authentication (missing %s param)' %
145 self._func.__name__) 149 (self._func.__name__, USER_SESSION_ATTR))
146 150
147 # get our arglist and check if we provided them as args 151 # get our arglist and check if we provided them as args
148 for arg in arglist: 152 for arg in arglist:
149 if arg == 'user': 153 if arg == USER_SESSION_ATTR:
150 # user is something translated from api key and this is 154 # USER_SESSION_ATTR is something translated from api key and
151 # checked before 155 # this is checked before so we don't need validate it
152 continue 156 continue
153 157
154 if not self._req_params or arg not in self._req_params: 158 if not self._req_params or arg not in self._req_params:
155 return jsonrpc_error(message='Missing %s arg in JSON DATA' % arg) 159 return jsonrpc_error(message='Missing %s arg in JSON DATA' % arg)
156 160
157 self._rpc_args = dict(user=u) 161 self._rpc_args = {USER_SESSION_ATTR:u}
158 self._rpc_args.update(self._req_params) 162 self._rpc_args.update(self._req_params)
159 163
160 self._rpc_args['action'] = self._req_method 164 self._rpc_args['action'] = self._req_method
161 self._rpc_args['environ'] = environ 165 self._rpc_args['environ'] = environ
162 self._rpc_args['start_response'] = start_response 166 self._rpc_args['start_response'] = start_response
181 """ 185 """
182 Implement dispatch interface specified by WSGIController 186 Implement dispatch interface specified by WSGIController
183 """ 187 """
184 try: 188 try:
185 raw_response = self._inspect_call(self._func) 189 raw_response = self._inspect_call(self._func)
186 print raw_response
187 if isinstance(raw_response, HTTPError): 190 if isinstance(raw_response, HTTPError):
188 self._error = str(raw_response) 191 self._error = str(raw_response)
189 except JSONRPCError as e: 192 except JSONRPCError as e:
190 self._error = str(e) 193 self._error = str(e)
191 except Exception as e: 194 except Exception as e:
221 224
222 if isinstance(func, types.MethodType): 225 if isinstance(func, types.MethodType):
223 return func 226 return func
224 else: 227 else:
225 raise AttributeError("No such method: %s" % self._req_method) 228 raise AttributeError("No such method: %s" % self._req_method)
229