Changeset - c82ef5ec8dcd
[Not reviewed]
default
0 6 0
Mads Kiilerich - 6 years ago 2019-12-26 16:09:30
mads@kiilerich.com
Grafted from: 41215423565b
lib: refactor _get_access_path as get_path_info

We will need it later when it gets more tricky to get the path from environ ...
6 files changed with 18 insertions and 16 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/api/__init__.py
Show inline comments
 
@@ -36,10 +36,10 @@ from tg import Response, TGController, r
 
from webob.exc import HTTPError, HTTPException
 

	
 
from kallithea.lib.auth import AuthUser
 
from kallithea.lib.base import _get_access_path
 
from kallithea.lib.base import _get_ip_addr as _get_ip
 
from kallithea.lib.base import get_path_info
 
from kallithea.lib.compat import json
 
from kallithea.lib.utils2 import safe_str, safe_unicode
 
from kallithea.lib.utils2 import safe_str
 
from kallithea.model.db import User
 

	
 

	
 
@@ -209,7 +209,7 @@ class JSONRPCController(TGController):
 

	
 
        log.info('IP: %s Request to %s time: %.3fs' % (
 
            self._get_ip_addr(environ),
 
            safe_unicode(_get_access_path(environ)), time.time() - start)
 
            get_path_info(environ), time.time() - start)
 
        )
 

	
 
        state.set_action(self._rpc_call, [])
kallithea/lib/base.py
Show inline comments
 
@@ -97,12 +97,13 @@ def _get_ip_addr(environ):
 
    return _filter_proxy(ip)
 

	
 

	
 
def _get_access_path(environ):
 
    """Return PATH_INFO from environ ... using tg.original_request if available."""
 
def get_path_info(environ):
 
    """Return unicode PATH_INFO from environ ... using tg.original_request if available.
 
    """
 
    org_req = environ.get('tg.original_request')
 
    if org_req is not None:
 
        environ = org_req.environ
 
    return environ.get('PATH_INFO')
 
    return safe_unicode(environ['PATH_INFO'])
 

	
 

	
 
def log_in_user(user, remember, is_external_auth, ip_addr):
 
@@ -526,7 +527,7 @@ class BaseController(TGController):
 

	
 
            log.info('IP: %s User: %s accessed %s',
 
                request.ip_addr, request.authuser,
 
                safe_unicode(_get_access_path(environ)),
 
                get_path_info(environ),
 
            )
 
            return super(BaseController, self).__call__(environ, context)
 
        except webob.exc.HTTPException as e:
kallithea/lib/middleware/permanent_repo_url.py
Show inline comments
 
@@ -21,7 +21,7 @@ middleware to handle permanent repo URLs
 

	
 

	
 
from kallithea.lib.utils import fix_repo_id_name
 
from kallithea.lib.utils2 import safe_str
 
from kallithea.lib.utils2 import safe_str, safe_unicode
 

	
 

	
 
class PermanentRepoUrl(object):
 
@@ -31,7 +31,9 @@ class PermanentRepoUrl(object):
 
        self.config = config
 

	
 
    def __call__(self, environ, start_response):
 
        path_info = environ['PATH_INFO']
 
        # Extract path_info as get_path_info does, but do it explicitly because
 
        # we also have to do the reverse operation when patching it back in
 
        path_info = safe_unicode(environ['PATH_INFO'])
 
        if path_info.startswith('/'): # it must
 
            path_info = '/' + safe_str(fix_repo_id_name(path_info[1:]))
 
            environ['PATH_INFO'] = path_info
kallithea/lib/middleware/simplegit.py
Show inline comments
 
@@ -31,7 +31,7 @@ Original author and date, and relevant c
 
import logging
 
import re
 

	
 
from kallithea.lib.base import BaseVCSController
 
from kallithea.lib.base import BaseVCSController, get_path_info
 
from kallithea.lib.hooks import log_pull_action
 
from kallithea.lib.middleware.pygrack import make_wsgi_app
 
from kallithea.lib.utils import make_ui
 
@@ -57,7 +57,7 @@ class SimpleGit(BaseVCSController):
 

	
 
    @classmethod
 
    def parse_request(cls, environ):
 
        path_info = environ.get('PATH_INFO', '')
 
        path_info = get_path_info(environ)
 
        m = GIT_PROTO_PAT.match(path_info)
 
        if m is None:
 
            return None
kallithea/lib/middleware/simplehg.py
Show inline comments
 
@@ -32,7 +32,7 @@ import logging
 
import os
 
import urllib
 

	
 
from kallithea.lib.base import BaseVCSController
 
from kallithea.lib.base import BaseVCSController, get_path_info
 
from kallithea.lib.utils import make_ui
 
from kallithea.lib.utils2 import safe_str, safe_unicode
 
from kallithea.lib.vcs.utils.hgcompat import hgweb_mod
 
@@ -99,7 +99,7 @@ class SimpleHg(BaseVCSController):
 
        http_accept = environ.get('HTTP_ACCEPT', '')
 
        if not http_accept.startswith('application/mercurial'):
 
            return None
 
        path_info = environ.get('PATH_INFO', '')
 
        path_info = get_path_info(environ)
 
        if not path_info.startswith('/'): # it must!
 
            return None
 

	
kallithea/lib/middleware/wrapper.py
Show inline comments
 
@@ -29,8 +29,7 @@ Original author and date, and relevant c
 
import logging
 
import time
 

	
 
from kallithea.lib.base import _get_access_path, _get_ip_addr
 
from kallithea.lib.utils2 import safe_unicode
 
from kallithea.lib.base import _get_ip_addr, get_path_info
 

	
 

	
 
log = logging.getLogger(__name__)
 
@@ -91,7 +90,7 @@ class RequestWrapper(object):
 
        meter = Meter(start_response)
 
        description = "Request from %s for %s" % (
 
            _get_ip_addr(environ),
 
            safe_unicode(_get_access_path(environ)),
 
            get_path_info(environ),
 
        )
 
        try:
 
            result = self.application(environ, meter.start_response)
0 comments (0 inline, 0 general)