Changeset - b3d8a3000a7f
[Not reviewed]
default
0 3 0
Mads Kiilerich (mads) - 5 years ago 2020-11-10 17:43:37
mads@kiilerich.com
Grafted from: 017e1e43eb39
lib: cleanup of _get_ip_addr
3 files changed with 8 insertions and 15 deletions:
0 comments (0 inline, 0 general)
kallithea/config/middleware/wrapper.py
Show inline comments
 
@@ -29,7 +29,7 @@ Original author and date, and relevant c
 
import logging
 
import time
 

	
 
from kallithea.lib.base import _get_ip_addr, get_path_info
 
from kallithea.lib.base import get_ip_addr, get_path_info
 

	
 

	
 
log = logging.getLogger(__name__)
 
@@ -91,7 +91,7 @@ class RequestWrapper(object):
 
    def __call__(self, environ, start_response):
 
        meter = Meter(start_response)
 
        description = "Request from %s for %s" % (
 
            _get_ip_addr(environ),
 
            get_ip_addr(environ),
 
            get_path_info(environ),
 
        )
 
        log.info("%s received", description)
kallithea/controllers/api/__init__.py
Show inline comments
 
@@ -37,8 +37,7 @@ from webob.exc import HTTPError, HTTPExc
 

	
 
from kallithea.lib import ext_json
 
from kallithea.lib.auth import AuthUser
 
from kallithea.lib.base import _get_ip_addr as _get_ip
 
from kallithea.lib.base import get_path_info
 
from kallithea.lib.base import get_ip_addr, get_path_info
 
from kallithea.lib.utils2 import ascii_bytes
 
from kallithea.model import db
 

	
 
@@ -83,9 +82,6 @@ class JSONRPCController(TGController):
 

	
 
     """
 

	
 
    def _get_ip_addr(self, environ):
 
        return _get_ip(environ)
 

	
 
    def _get_method_args(self):
 
        """
 
        Return `self._rpc_args` to dispatched controller method
 
@@ -103,7 +99,7 @@ class JSONRPCController(TGController):
 

	
 
        environ = state.request.environ
 
        start = time.time()
 
        ip_addr = self._get_ip_addr(environ)
 
        ip_addr = get_ip_addr(environ)
 
        self._req_id = None
 
        if 'CONTENT_LENGTH' not in environ:
 
            log.debug("No Content-Length")
 
@@ -208,7 +204,7 @@ class JSONRPCController(TGController):
 
        self._rpc_args['environ'] = environ
 

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

	
kallithea/lib/base.py
Show inline comments
 
@@ -78,7 +78,7 @@ def _filter_proxy(ip):
 
    return ip
 

	
 

	
 
def _get_ip_addr(environ):
 
def get_ip_addr(environ):
 
    proxy_key = 'HTTP_X_REAL_IP'
 
    proxy_key2 = 'HTTP_X_FORWARDED_FOR'
 
    def_key = 'REMOTE_ADDR'
 
@@ -300,9 +300,6 @@ class BaseVCSController(object):
 

	
 
        return True
 

	
 
    def _get_ip_addr(self, environ):
 
        return _get_ip_addr(environ)
 

	
 
    def __call__(self, environ, start_response):
 
        try:
 
            # try parsing a request for this VCS - if it fails, call the wrapped app
 
@@ -324,7 +321,7 @@ class BaseVCSController(object):
 
            #======================================================================
 
            # CHECK PERMISSIONS
 
            #======================================================================
 
            ip_addr = self._get_ip_addr(environ)
 
            ip_addr = get_ip_addr(environ)
 
            user, response_app = self._authorize(environ, parsed_request.action, parsed_request.repo_name, ip_addr)
 
            if response_app is not None:
 
                return response_app(environ, start_response)
 
@@ -488,7 +485,7 @@ class BaseController(TGController):
 

	
 
    def __call__(self, environ, context):
 
        try:
 
            ip_addr = _get_ip_addr(environ)
 
            ip_addr = get_ip_addr(environ)
 
            self._basic_security_checks()
 

	
 
            api_key = request.GET.get('api_key')
0 comments (0 inline, 0 general)