@@ -112,24 +112,25 @@ class SimpleGit(BaseVCSController):
log.debug('Extracted repo name is %s' % repo_name)
except:
return HTTPInternalServerError()(environ, start_response)
#======================================================================
# GET ACTION PULL or PUSH
action = self.__get_action(environ)
# CHECK ANONYMOUS PERMISSION
if action in ['pull', 'push']:
anonymous_user = self.__get_user('default')
username = anonymous_user.username
anonymous_perm = self._check_permission(action, anonymous_user,
repo_name)
if anonymous_perm is not True or anonymous_user.active is False:
if anonymous_perm is not True:
log.debug('Not enough credentials to access this '
'repository as anonymous user')
if anonymous_user.active is False:
log.debug('Anonymous access is disabled, running '
@@ -160,33 +161,31 @@ class SimpleGit(BaseVCSController):
try:
user = self.__get_user(username)
if user is None or not user.active:
return HTTPForbidden()(environ, start_response)
username = user.username
log.error(traceback.format_exc())
return HTTPInternalServerError()(environ,
start_response)
#check permissions for this repository
perm = self._check_permission(action, user,
perm = self._check_permission(action, user, repo_name)
if perm is not True:
#===================================================================
# GIT REQUEST HANDLING
repo_path = safe_str(os.path.join(self.basepath, repo_name))
log.debug('Repository path is %s' % repo_path)
# quick check if that dir exists...
if is_valid_repo(repo_name, self.basepath) is False:
return HTTPNotFound()(environ, start_response)
#invalidate cache on push
if action == 'push':
self._invalidate_cache(repo_name)
log.info('%s action on GIT repo "%s"' % (action, repo_name))
@@ -194,25 +193,24 @@ class SimpleGit(BaseVCSController):
return app(environ, start_response)
except Exception:
def __make_app(self, repo_name, repo_path):
"""
Make an wsgi application using dulserver
:param repo_name: name of the repository
:param repo_path: full path to the repository
_d = {'/' + repo_name: Repo(repo_path)}
backend = dulserver.DictBackend(_d)
gitserve = HTTPGitApplication(backend)
return gitserve
def __get_repository(self, environ):
Get's repository name out of PATH_INFO header
:param environ: environ where PATH_INFO is stored
@@ -220,28 +218,33 @@ class SimpleGit(BaseVCSController):
environ['PATH_INFO'] = self._get_by_id(environ['PATH_INFO'])
repo_name = GIT_PROTO_PAT.match(environ['PATH_INFO']).group(1)
raise
return repo_name
def __get_user(self, username):
return User.get_by_username(username)
def __get_action(self, environ):
"""Maps git request commands into a pull or push command.
Maps git request commands into a pull or push command.
:param environ:
service = environ['QUERY_STRING'].split('=')
if len(service) > 1:
service_cmd = service[1]
mapping = {
'git-receive-pack': 'push',
'git-upload-pack': 'pull',
}
return mapping.get(service_cmd,
service_cmd if service_cmd else 'other')
op = mapping[service_cmd]
self._git_stored_op = op
return op
else:
return 'other'
# try to fallback to stored variable as we don't know if the last
# operation is pull/push
op = getattr(self, '_git_stored_op', 'pull')
Status change: