Commits

Lukasz Balcerzak  committed 62da3bc

Started to implement authentication for git http - doesn't check permissions yet and credentials must be specified within repository url

  • Participants
  • Parent commits 94ff06c

Comments (0)

Files changed (2)

File projector/contrib/git/utils.py

     def start_response(status, headers):
         response.status_code = int(status[:3])
         for key, val in headers:
-            logging.info("%s: %s" % (key, val))
             response[key] = val
         return response.write
     env = copy.copy(request.META)

File projector/contrib/git/views.py

         logging.debug("Path is: %s" % self.request.META['PATH_INFO'])
         logging.debug("Query is: %s" % self.request.META['QUERY_STRING'])
 
+    def get_required_perms(self):
+        if is_git_request(self.request):
+            # Let undelying code verify permissions
+            return []
+        return super(ProjectGitBaseView, self).get_required_perms()
+
 
 class ProjectGitHandler(ProjectGitBaseView):
 
     def response(self, request, username, project_slug):
         try:
+            auth_response = self.get_authed_user()
+            if auth_response:
+                return auth_response
             git_server = GitWebServer(self.project.repository)
             response = git_server.get_response(request)
         except Exception, err:
             raise err
         return response
 
+    def get_authed_user(self):
+        if self.project.is_public():
+            return None
+        from vcs.web.simplevcs.utils import ask_basic_auth, basic_auth
+        # Check if user have been already authorized or ask to
+        self.request.user = basic_auth(self.request)
+        if self.request.user is None:
+            return ask_basic_auth(self.request,
+                realm=self.project.config.basic_realm)
+
+
 
 class GitWebServer(object):