def handle_request( self, trans, **kwd ): # The os command that results in this method being called will look something like: # hg clone http://[email protected]:9009/repos/test/convert_characters1 hg_version = mercurial.__version__.version cmd = kwd.get( 'cmd', None ) hgweb_config = trans.app.hgweb_config_manager.hgweb_config def make_web_app(): hgwebapp = hgwebdir( hgweb_config ) return hgwebapp wsgi_app = wsgiapplication( make_web_app ) if hg_version >= '2.2.3' and cmd == 'pushkey': # When doing an "hg push" from the command line, the following commands, in order, will be retrieved from environ, depending # upon the mercurial version being used. In mercurial version 2.2.3, section 15.2. Command changes includes a new feature: # pushkey: add hooks for pushkey/listkeys (see http://mercurial.selenic.com/wiki/WhatsNew#Mercurial_2.2.3_.282012-07-01.29). # We require version 2.2.3 since the pushkey hook was added in that version. # If mercurial version >= '2.2.3': capabilities -> batch -> branchmap -> unbundle -> listkeys -> pushkey path_info = kwd.get( 'path_info', None ) if path_info: owner, name = path_info.split( '/' ) repository = get_repository_by_name_and_owner( trans.app, name, owner ) if repository: if hg_version >= '2.2.3': # Set metadata using the repository files on disk. error_message, status = set_repository_metadata( trans, repository ) if status == 'ok' and error_message: log.debug( "Successfully reset metadata on repository %s, but encountered problem: %s" % ( repository.name, error_message ) ) elif status != 'ok' and error_message: log.debug( "Error resetting metadata on repository %s: %s" % ( repository.name, error_message ) ) return wsgi_app
def handle_request(self, trans, **kwd): # The os command that results in this method being called will look something like: # hg clone http://[email protected]:9009/repos/test/convert_characters1 hgweb_config = trans.app.hgweb_config_manager.hgweb_config def make_web_app(): hgwebapp = hgwebdir(hgweb_config.encode('utf-8')) return hgwebapp wsgi_app = wsgiapplication(make_web_app) repository = None path_info = kwd.get('path_info', None) if path_info and len(path_info.split('/')) == 2: owner, name = path_info.split('/') repository = get_repository_by_name_and_owner( trans.app, name, owner) if repository: if repository.deprecated: raise ObjectNotFound( "Requested repository not found or deprecated.") cmd = kwd.get('cmd', None) if cmd == 'getbundle': times_downloaded = repository.times_downloaded times_downloaded += 1 repository.times_downloaded = times_downloaded trans.sa_session.add(repository) trans.sa_session.flush() return wsgi_app
def handle_request(self, trans, **kwd): # The os command that results in this method being called will look something like: # hg clone http://[email protected]:9009/repos/test/convert_characters1 hg_version = mercurial.__version__.version cmd = kwd.get("cmd", None) hgweb_config = trans.app.hgweb_config_manager.hgweb_config def make_web_app(): hgwebapp = hgwebdir(hgweb_config) return hgwebapp wsgi_app = wsgiapplication(make_web_app) if hg_version >= "2.2.3" and cmd == "pushkey": # When doing an "hg push" from the command line, the following commands, in order, will be # retrieved from environ, depending upon the mercurial version being used. In mercurial # version 2.2.3, section 15.2. Command changes includes a new feature: # pushkey: add hooks for pushkey/listkeys # (see http://mercurial.selenic.com/wiki/WhatsNew#Mercurial_2.2.3_.282012-07-01.29). # We require version 2.2.3 since the pushkey hook was added in that version. # If mercurial version >= '2.2.3': capabilities -> batch -> branchmap -> unbundle -> listkeys -> pushkey path_info = kwd.get("path_info", None) if path_info: owner, name = path_info.split("/") repository = get_repository_by_name_and_owner(trans.app, name, owner) if repository: if hg_version >= "2.2.3": # Update the repository on disk to the tip revision, because the web upload # form uses the on-disk working directory. If the repository is not updated # on disk, pushing from the command line and then uploading via the web # interface will result in a new head being created. repo = hg.repository(ui.ui(), repository.repo_path(trans.app)) update_repository(repo, ctx_rev=None) repository_clone_url = generate_clone_url_for_repository_in_tool_shed(trans.user, repository) # Set metadata using the repository files on disk. rmm = repository_metadata_manager.RepositoryMetadataManager( app=trans.app, user=trans.user, repository=repository, changeset_revision=repository.tip(trans.app), repository_clone_url=repository_clone_url, relative_install_dir=repository.repo_path(trans.app), repository_files_dir=None, resetting_all_metadata_on_repository=False, updating_installed_repository=False, persist=False, ) error_message, status = rmm.set_repository_metadata(trans.request.host) if status == "ok" and error_message: log.debug( "Successfully reset metadata on repository %s owned by %s, but encountered problem: %s" % (str(repository.name), str(repository.user.username), error_message) ) elif status != "ok" and error_message: log.debug( "Error resetting metadata on repository %s owned by %s: %s" % (str(repository.name), str(repository.user.username), error_message) ) return wsgi_app
def handle_request(self, trans, **kwd): # The os command that results in this method being called will look something like: # hg clone http://[email protected]:9009/repos/test/convert_characters1 hg_version = mercurial.__version__.version cmd = kwd.get('cmd', None) hgweb_config = trans.app.hgweb_config_manager.hgweb_config def make_web_app(): hgwebapp = hgwebdir(hgweb_config) return hgwebapp wsgi_app = wsgiapplication(make_web_app) if hg_version >= '2.2.3' and cmd == 'pushkey': # When doing an "hg push" from the command line, the following commands, in order, will be # retrieved from environ, depending upon the mercurial version being used. In mercurial # version 2.2.3, section 15.2. Command changes includes a new feature: # pushkey: add hooks for pushkey/listkeys # (see http://mercurial.selenic.com/wiki/WhatsNew#Mercurial_2.2.3_.282012-07-01.29). # We require version 2.2.3 since the pushkey hook was added in that version. # If mercurial version >= '2.2.3': capabilities -> batch -> branchmap -> unbundle -> listkeys -> pushkey path_info = kwd.get('path_info', None) if path_info: owner, name = path_info.split('/') repository = get_repository_by_name_and_owner( trans.app, name, owner) if repository: if hg_version >= '2.2.3': # Update the repository on disk to the tip revision, because the web upload # form uses the on-disk working directory. If the repository is not updated # on disk, pushing from the command line and then uploading via the web # interface will result in a new head being created. repo = hg.repository(ui.ui(), repository.repo_path(trans.app)) update_repository(repo, ctx_rev=None) repository_clone_url = generate_clone_url_for_repository_in_tool_shed( trans.user, repository) # Set metadata using the repository files on disk. rmm = repository_metadata_manager.RepositoryMetadataManager( app=trans.app, user=trans.user, repository=repository, changeset_revision=repository.tip(trans.app), repository_clone_url=repository_clone_url, relative_install_dir=repository.repo_path( trans.app), repository_files_dir=None, resetting_all_metadata_on_repository=False, updating_installed_repository=False, persist=False) error_message, status = rmm.set_repository_metadata( trans.request.host) if status == 'ok' and error_message: log.debug( "Successfully reset metadata on repository %s owned by %s, but encountered problem: %s" % \ ( str( repository.name ), str( repository.user.username ), error_message ) ) elif status != 'ok' and error_message: log.debug( "Error resetting metadata on repository %s owned by %s: %s" % \ ( str( repository.name ), str( repository.user.username ), error_message ) ) return wsgi_app
def handle_request( self, trans, **kwd ): # The os command that results in this method being called will look something like # hg clone http://[email protected]:9009/repos/test/convert_characters1 cmd = kwd.get( 'cmd', None ) wsgi_app = wsgiapplication( make_web_app ) # Hack: Add a parameter to requests for which we do not want all repository metadata reset. reset_metadata = not ( kwd.get( 'no_reset', False ) ) if cmd == 'listkeys' and reset_metadata: # This possibly results from an "hg push" from the command line. When doing this, the following 7 commands, in order, # will be retrieved from environ: between -> capabilities -> heads -> branchmap -> unbundle -> unbundle -> listkeys path_info = kwd.get( 'path_info', None ) if path_info: owner, name = path_info.split( '/' ) repository = get_repository_by_name_and_owner( trans, name, owner ) if repository: reset_all_repository_metadata( trans, trans.security.encode_id( repository.id ) ) return wsgi_app
def handle_request(self, trans, **kwd): # The os command that results in this method being called will look something like # hg clone http://[email protected]:9009/repos/test/convert_characters1 cmd = kwd.get('cmd', None) wsgi_app = wsgiapplication(make_web_app) # Hack: Add a parameter to requests for which we do not want all repository metadata reset. reset_metadata = not (kwd.get('no_reset', False)) if cmd == 'listkeys' and reset_metadata: # This possibly results from an "hg push" from the command line. When doing this, the following 7 commands, in order, # will be retrieved from environ: between -> capabilities -> heads -> branchmap -> unbundle -> unbundle -> listkeys path_info = kwd.get('path_info', None) if path_info: owner, name = path_info.split('/') repository = get_repository_by_name_and_owner( trans, name, owner) if repository: reset_all_repository_metadata( trans, trans.security.encode_id(repository.id)) return wsgi_app
def handle_request( self, trans, **kwd ): # The os command that results in this method being called will look something like # hg clone http://[email protected]:9009/repos/test/convert_characters1 cmd = kwd.get( 'cmd', None ) wsgi_app = wsgiapplication( make_web_app ) # Hack: Add a parameter to requests for which we do not want all repository metadata reset. reset_metadata = not ( kwd.get( 'no_reset', False ) ) if cmd == 'listkeys' and reset_metadata: # This possibly results from an "hg push" from the command line. When doing this, the following 7 commands, in order, # will be retrieved from environ: between -> capabilities -> heads -> branchmap -> unbundle -> unbundle -> listkeys path_info = kwd.get( 'path_info', None ) if path_info: owner, name = path_info.split( '/' ) repository = get_repository_by_name_and_owner( trans, name, owner ) if repository: error_message, status = reset_all_metadata_on_repository( trans, trans.security.encode_id( repository.id ) ) if status not in [ 'ok' ] and error_message: log.debug( "Error resetting metadata on repository '%s': %s" % ( str( repository.name ), str( error_message ) ) ) elif status in [ 'ok' ] and error_message: log.debug( "Successfully reset metadata on repository %s, but encountered problem: %s" % ( str( repository.name ), str( error_message ) ) ) return wsgi_app
def handle_request(self, trans, **kwd): # The os command that results in this method being called will look something like: # hg clone http://[email protected]:9009/repos/test/convert_characters1 hgweb_config = trans.app.hgweb_config_manager.hgweb_config cmd = kwd.get('cmd', None) def make_web_app(): hgwebapp = hgwebdir(hgweb_config) return hgwebapp wsgi_app = wsgiapplication(make_web_app) if cmd == 'getbundle': path_info = kwd.get('path_info', None) if path_info: owner, name = path_info.split('/') repository = get_repository_by_name_and_owner(trans.app, name, owner) if repository: times_downloaded = repository.times_downloaded times_downloaded += 1 repository.times_downloaded = times_downloaded trans.sa_session.add(repository) trans.sa_session.flush() return wsgi_app
def handle_request(self, trans, **kwd): # The os command that results in this method being called will look something like: # hg clone http://[email protected]:9009/repos/test/convert_characters1 hgweb_config = trans.app.hgweb_config_manager.hgweb_config cmd = kwd.get('cmd', None) def make_web_app(): hgwebapp = hgwebdir(hgweb_config) return hgwebapp wsgi_app = wsgiapplication(make_web_app) if cmd == 'getbundle': path_info = kwd.get('path_info', None) if path_info: owner, name = path_info.split('/') repository = get_repository_by_name_and_owner( trans.app, name, owner) if repository: times_downloaded = repository.times_downloaded times_downloaded += 1 repository.times_downloaded = times_downloaded trans.sa_session.add(repository) trans.sa_session.flush() return wsgi_app
def start(environ, start_response): toto = wsgiapplication(make_web_app) return toto (environ, start_response)
def __call__(self, environ, start_response): if not is_mercurial(environ): return self.application(environ, start_response) proxy_key = 'HTTP_X_REAL_IP' def_key = 'REMOTE_ADDR' self.ipaddr = environ.get(proxy_key, environ.get(def_key, '0.0.0.0')) # skip passing error to error controller environ['pylons.status_code_redirect'] = True #====================================================================== # GET ACTION PULL or PUSH #====================================================================== self.action = self.__get_action(environ) try: #================================================================== # GET REPOSITORY NAME #================================================================== self.repo_name = self.__get_repository(environ) except: return HTTPInternalServerError()(environ, start_response) #====================================================================== # CHECK ANONYMOUS PERMISSION #====================================================================== if self.action in ['pull', 'push']: anonymous_user = self.__get_user('default') self.username = anonymous_user.username anonymous_perm = self.__check_permission(self.action, anonymous_user, self.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 ' 'authentication') #============================================================== # DEFAULT PERM FAILED OR ANONYMOUS ACCESS IS DISABLED SO WE # NEED TO AUTHENTICATE AND ASK FOR AUTH USER PERMISSIONS #============================================================== if not REMOTE_USER(environ): self.authenticate.realm = \ safe_str(self.config['rhodecode_realm']) result = self.authenticate(environ) if isinstance(result, str): AUTH_TYPE.update(environ, 'basic') REMOTE_USER.update(environ, result) else: return result.wsgi_application(environ, start_response) #============================================================== # CHECK PERMISSIONS FOR THIS REQUEST USING GIVEN USERNAME FROM # BASIC AUTH #============================================================== if self.action in ['pull', 'push']: username = REMOTE_USER(environ) try: user = self.__get_user(username) self.username = user.username except: log.error(traceback.format_exc()) return HTTPInternalServerError()(environ, start_response) #check permissions for this repository perm = self.__check_permission(self.action, user, self.repo_name) if perm is not True: return HTTPForbidden()(environ, start_response) self.extras = {'ip': self.ipaddr, 'username': self.username, 'action': self.action, 'repository': self.repo_name} #====================================================================== # MERCURIAL REQUEST HANDLING #====================================================================== environ['PATH_INFO'] = '/' # since we wrap into hgweb, reset the path self.baseui = make_ui('db') self.basepath = self.config['base_path'] self.repo_path = os.path.join(self.basepath, self.repo_name) #quick check if that dir exists... if check_repo_fast(self.repo_name, self.basepath): return HTTPNotFound()(environ, start_response) try: app = wsgiapplication(self.__make_app) except RepoError, e: if str(e).find('not found') != -1: return HTTPNotFound()(environ, start_response)