comparison rhodecode/lib/middleware/simplegit.py @ 2092:ecd59c28f432

merged beta into stable
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 02 Mar 2012 21:57:01 +0200
parents 9ab21c5ddb84 2632a49cb402
children dc2584ba5fbc
comparison
equal deleted inserted replaced
2074:6c6718c06ea2 2092:ecd59c28f432
119 action = self.__get_action(environ) 119 action = self.__get_action(environ)
120 120
121 #====================================================================== 121 #======================================================================
122 # CHECK ANONYMOUS PERMISSION 122 # CHECK ANONYMOUS PERMISSION
123 #====================================================================== 123 #======================================================================
124
124 if action in ['pull', 'push']: 125 if action in ['pull', 'push']:
125 anonymous_user = self.__get_user('default') 126 anonymous_user = self.__get_user('default')
126 username = anonymous_user.username 127 username = anonymous_user.username
127 anonymous_perm = self._check_permission(action, anonymous_user, 128 anonymous_perm = self._check_permission(action, anonymous_user,
128 repo_name) 129 repo_name)
167 log.error(traceback.format_exc()) 168 log.error(traceback.format_exc())
168 return HTTPInternalServerError()(environ, 169 return HTTPInternalServerError()(environ,
169 start_response) 170 start_response)
170 171
171 #check permissions for this repository 172 #check permissions for this repository
172 perm = self._check_permission(action, user, 173 perm = self._check_permission(action, user, repo_name)
173 repo_name)
174 if perm is not True: 174 if perm is not True:
175 return HTTPForbidden()(environ, start_response) 175 return HTTPForbidden()(environ, start_response)
176 176
177 #=================================================================== 177 #===================================================================
178 # GIT REQUEST HANDLING 178 # GIT REQUEST HANDLING
179 #=================================================================== 179 #===================================================================
180
181 repo_path = safe_str(os.path.join(self.basepath, repo_name)) 180 repo_path = safe_str(os.path.join(self.basepath, repo_name))
182 log.debug('Repository path is %s' % repo_path) 181 log.debug('Repository path is %s' % repo_path)
183 182
184 # quick check if that dir exists... 183 # quick check if that dir exists...
185 if is_valid_repo(repo_name, self.basepath) is False: 184 if is_valid_repo(repo_name, self.basepath) is False:
201 Make an wsgi application using dulserver 200 Make an wsgi application using dulserver
202 201
203 :param repo_name: name of the repository 202 :param repo_name: name of the repository
204 :param repo_path: full path to the repository 203 :param repo_path: full path to the repository
205 """ 204 """
206
207 _d = {'/' + repo_name: Repo(repo_path)} 205 _d = {'/' + repo_name: Repo(repo_path)}
208 backend = dulserver.DictBackend(_d) 206 backend = dulserver.DictBackend(_d)
209 gitserve = HTTPGitApplication(backend) 207 gitserve = HTTPGitApplication(backend)
210 208
211 return gitserve 209 return gitserve
227 225
228 def __get_user(self, username): 226 def __get_user(self, username):
229 return User.get_by_username(username) 227 return User.get_by_username(username)
230 228
231 def __get_action(self, environ): 229 def __get_action(self, environ):
232 """Maps git request commands into a pull or push command. 230 """
231 Maps git request commands into a pull or push command.
233 232
234 :param environ: 233 :param environ:
235 """ 234 """
236 service = environ['QUERY_STRING'].split('=') 235 service = environ['QUERY_STRING'].split('=')
236
237 if len(service) > 1: 237 if len(service) > 1:
238 service_cmd = service[1] 238 service_cmd = service[1]
239 mapping = { 239 mapping = {
240 'git-receive-pack': 'push', 240 'git-receive-pack': 'push',
241 'git-upload-pack': 'pull', 241 'git-upload-pack': 'pull',
242 } 242 }
243 243 op = mapping[service_cmd]
244 return mapping.get(service_cmd, 244 self._git_stored_op = op
245 service_cmd if service_cmd else 'other') 245 return op
246 else: 246 else:
247 return 'other' 247 # try to fallback to stored variable as we don't know if the last
248 # operation is pull/push
249 op = getattr(self, '_git_stored_op', 'pull')
250 return op