Beispiel #1
0
def git_endpoint(api_ctx, course_identifier, git_path):
    # type: (APIContext, Text, Text) -> http.HttpResponse

    course = api_ctx.course
    request = api_ctx.request

    if not api_ctx.has_permission(pperm.use_git_endpoint):
        raise PermissionDenied("insufficient privileges")

    from course.content import get_course_repo
    repo = get_course_repo(course)

    from course.content import SubdirRepoWrapper
    if isinstance(repo, SubdirRepoWrapper):
        true_repo = repo.repo
    else:
        true_repo = cast(dulwich.repo.Repo, repo)

    base_path = reverse(git_endpoint, args=(course_identifier, ""))
    assert base_path.endswith("/")
    base_path = base_path[:-1]

    import dulwich.web as dweb
    backend = dweb.DictBackend({"/": true_repo})
    app = dweb.make_wsgi_chain(backend)

    return call_wsgi_app(app, request, base_path)
Beispiel #2
0
    def _MakeRepo(self, set_latest=True, start_server=True, branch=None):
        """Make a git repository to test against.

    Args:
      set_latest: (bool) Create 'refs/tags/latest' pointing at the first
        commit.
      start_server: (bool) Start an HTTP server.
      branch: (str or None) branch to check in on.
    """
        self.repo = repo.Repo.init(self.repo_path, mkdir=True)

        commit_id = self._CommitFile(b'first contents', b'first commit',
                                     branch)
        if set_latest:
            self.repo[b'refs/tags/latest'] = commit_id

        # This second commit will just show up under refs/heads/master, we add it
        # to verify that we're pulling from "latest" tag, and not from "master".
        self._CommitFile(b'second contents', b'second commit')

        if start_server:
            backend = server.DictBackend({'/': self.repo})
            self.server = (simple_server.make_server(
                'localhost',
                0,
                web.make_wsgi_chain(backend),
                handler_class=web.WSGIRequestHandlerLogger,
                server_class=self._WSGIServerClass()))
            self.server_thread = threading.Thread(
                target=self.server.serve_forever)
            self.server_thread.start()
Beispiel #3
0
 def _make_app(self, backend):
     app = make_wsgi_chain(backend, handlers=self._handlers())
     to_check = app
     # peel back layers until we're at the base application
     while not issubclass(to_check.__class__, HTTPGitApplication):
         to_check = to_check.app
     self._check_app(to_check)
     return app
Beispiel #4
0
 def _make_app(self, backend):
     app = make_wsgi_chain(backend, handlers=self._handlers())
     to_check = app
     # peel back layers until we're at the base application
     while not issubclass(to_check.__class__, HTTPGitApplication):
         to_check = to_check.app
     self._check_app(to_check)
     return app
Beispiel #5
0
    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 = make_wsgi_chain(backend)

        return gitserve
Beispiel #6
0
    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 = make_wsgi_chain(backend)

        return gitserve
Beispiel #7
0
def web_daemon(path=".", address=None, port=None):
    """Run a daemon serving Git requests over HTTP.

    :param path: Path to the directory to serve
    :param address: Optional address to listen on (defaults to ::)
    :param port: Optional port to listen on (defaults to 80)
    """
    from dulwich.web import make_wsgi_chain, make_server, WSGIRequestHandlerLogger, WSGIServerLogger

    backend = FileSystemBackend(path)
    app = make_wsgi_chain(backend)
    server = make_server(address, port, app, handler_class=WSGIRequestHandlerLogger, server_class=WSGIServerLogger)
    server.serve_forever()
Beispiel #8
0
def web_daemon(path=".", address=None, port=None):
    """Run a daemon serving Git requests over HTTP.

    :param path: Path to the directory to serve
    :param address: Optional address to listen on (defaults to ::)
    :param port: Optional port to listen on (defaults to 80)
    """
    from dulwich.web import (make_wsgi_chain, make_server,
                             WSGIRequestHandlerLogger, WSGIServerLogger)

    backend = FileSystemBackend(path)
    app = make_wsgi_chain(backend)
    server = make_server(address,
                         port,
                         app,
                         handler_class=WSGIRequestHandlerLogger,
                         server_class=WSGIServerLogger)
    server.serve_forever()
Beispiel #9
0
 def _make_app(self, backend):
     return make_wsgi_chain(backend, dumb=True)
Beispiel #10
0
 def _make_app(self, backend):
     return make_wsgi_chain(backend, dumb=True)