# HG changeset patch # User Mads Kiilerich # Date 2020-11-10 17:43:37 # Node ID b3d8a3000a7f54773e54350479e498031f8847e4 # Parent 5e8f46e868e8c73622ef0af7b796b75b50305e07 lib: cleanup of _get_ip_addr diff --git a/kallithea/config/middleware/wrapper.py b/kallithea/config/middleware/wrapper.py --- a/kallithea/config/middleware/wrapper.py +++ b/kallithea/config/middleware/wrapper.py @@ -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) diff --git a/kallithea/controllers/api/__init__.py b/kallithea/controllers/api/__init__.py --- a/kallithea/controllers/api/__init__.py +++ b/kallithea/controllers/api/__init__.py @@ -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) ) diff --git a/kallithea/lib/base.py b/kallithea/lib/base.py --- a/kallithea/lib/base.py +++ b/kallithea/lib/base.py @@ -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')