Commits

Lukasz Balcerzak committed 01c1bfb

Pre git authentication freeze

Comments (0)

Files changed (4)

projector/contrib/git/githttp.py

 import logging
 
 from django.http import Http404, HttpResponse
+from django.utils.translation import ugettext as _
+from django.template.defaultfilters import filesizeformat
 
 from dulwich.pack import write_pack_data
 from dulwich.protocol import ProtocolFile
 
 class GitWebServer(object):
 
+    class Type:
+        READ = 'read'
+        WRITE = 'write'
+        UNSPECIFIED = 'unspecified'
+
     def __init__(self, repository):
         self.repository = repository
         self.response = HttpResponse()
 
     def get_response(self, request):
-        #backend = DictBackend({'/': Repo(self.repository.path)})
         backend = ProjectorGitBackend(self.repository)
         app = GitApplication(backend, handlers={
             'git-upload-pack': ProjectorUploadPackHandler,
         write_pack_data(ProtocolFile(None, write), objects_iter,
                         len(objects_iter))
         #self.progress("how was that, then?\n")
+        size = self.backend.repository.info.size
+        msg = _('Repository size: %s\n' % filesizeformat(size))
+        logging.info(msg)
+        self.progress(msg)
         # we are done
         self.proto.write("0000")
 

projector/contrib/git/views.py

 from projector.views.project import ProjectView
 
 from vcs.web.simplevcs.utils import log_error, ask_basic_auth, basic_auth
+from vcs.web.simplevcs.signals import pre_clone, post_clone, pre_push, post_push
 
 
 class ProjectGitBaseView(ProjectView):
+    """
+    Base view class for git http handler.
+
+    Extra attributes:
+
+    - ``type``: returns ``READ`` or ``WRITE`` value of ``Type`` subclass of
+      ``projector.contrib.git.githttp.GitWebServer``. It specifies if user
+      is reading from or writing into the repository.
+
+    Signals:
+
+    Basing on ``type`` attribute, git handler sends one of ``pre_clone``,
+    ``post_clone``, ``pre_push`` or ``post_push`` signal from
+    ``vcs.web.simplevcs.signals``.
+    """
 
     csrf_exempt = True
 
 
     def response(self, request, username, project_slug):
         try:
+            #if 'git-upload-pack' in self.request.META['PATH_INFO']:
+                #self.type = GitWebServer.Type.READ
+                #pre_push.send(sender=self,
+                    #repo_path=self.project.repository.path,
+                    #ip=self.request.META.get('REMOTE_ADDR', ''),
+                    #username=self.request.user.username)
+            #elif 'git-receive-pack' in self.request.META['PATH_INFO']:
+                #self.type = GitWebServer.Type.WRITE
+                #pre_clone.send(sender=self,
+                    #repo_path=self.project.repository.path,
+                    #ip=self.request.META.get('REMOTE_ADDR', ''),
+                    #username=self.request.user.username)
+            #else:
+                #self.type = GitWebServer.Type.UNSPECIFIED
+
             auth_response = self.get_authed_user()
             if auth_response:
                 return auth_response
             git_server = GitWebServer(self.project.repository)
             response = git_server.get_response(request)
+            #if self.is_read():
+                #post_clone.send(sender=self, repo_path=self.project.repository.path,
+                    #ip=self.request.META.get('REMOTE_ADDR', ''),
+                    #username=self.request.username)
+            #elif self.is_write():
+                #post_push.send(sender=self, repo_path=self.project.repository.path,
+                    #ip=self.request.META.get('REMOTE_ADDR', ''),
+                    #username=self.request.username)
         except Exception, err:
             log_error(err)
             raise err
+
+        #print response
         return response
 
     def get_authed_user(self):
                 realm=self.project.config.basic_realm)
         raise PermissionDenied
 
+    def is_read(self):
+        return self.type == GitWebServer.Type.READ
+
+    def is_write(self):
+        return self.type == GitWebServer.Type.WRITE
+
+

projector/templates/projector/project/detail.html

         </ul>
         {% endif %}
 
-        {% if project.repository %}
+        {% if project.repository.pk %}
         {% with project.get_clone_cmd|put_username_into_url:user as clone_url %}
         <ul class="messages">
             <li class="message message-info">{% trans "Clone repository" %}:

projector/utils/package.py

         from vcs.exceptions import RepositoryError, VCSError
         repopath = os.path.join(os.path.dirname(__file__), '..', '..')
         scm = get_scm(repopath)[0]
-        repo = get_repo(scm, repopath)
+        repo = get_repo(path=repopath, alias=scm)
         tip = repo.get_changeset()
         return (tip.revision, tip.id)
     except (ImportError, RepositoryError, VCSError), err:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.