Mercurial > kallithea
comparison kallithea/controllers/api/__init__.py @ 8791:b3d8a3000a7f
lib: cleanup of _get_ip_addr
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Tue, 10 Nov 2020 17:43:37 +0100 |
parents | 5e46f73f0d1c |
children | 4f0de9468da3 |
comparison
equal
deleted
inserted
replaced
8790:5e8f46e868e8 | 8791:b3d8a3000a7f |
---|---|
35 from tg import Response, TGController, request, response | 35 from tg import Response, TGController, request, response |
36 from webob.exc import HTTPError, HTTPException | 36 from webob.exc import HTTPError, HTTPException |
37 | 37 |
38 from kallithea.lib import ext_json | 38 from kallithea.lib import ext_json |
39 from kallithea.lib.auth import AuthUser | 39 from kallithea.lib.auth import AuthUser |
40 from kallithea.lib.base import _get_ip_addr as _get_ip | 40 from kallithea.lib.base import get_ip_addr, get_path_info |
41 from kallithea.lib.base import get_path_info | |
42 from kallithea.lib.utils2 import ascii_bytes | 41 from kallithea.lib.utils2 import ascii_bytes |
43 from kallithea.model import db | 42 from kallithea.model import db |
44 | 43 |
45 | 44 |
46 log = logging.getLogger('JSONRPC') | 45 log = logging.getLogger('JSONRPC') |
81 Sub-classes should catch their exceptions and raise JSONRPCError | 80 Sub-classes should catch their exceptions and raise JSONRPCError |
82 if they want to pass meaningful errors to the client. | 81 if they want to pass meaningful errors to the client. |
83 | 82 |
84 """ | 83 """ |
85 | 84 |
86 def _get_ip_addr(self, environ): | |
87 return _get_ip(environ) | |
88 | |
89 def _get_method_args(self): | 85 def _get_method_args(self): |
90 """ | 86 """ |
91 Return `self._rpc_args` to dispatched controller method | 87 Return `self._rpc_args` to dispatched controller method |
92 chosen by __call__ | 88 chosen by __call__ |
93 """ | 89 """ |
101 # Since we are here we should respond as JSON | 97 # Since we are here we should respond as JSON |
102 response.content_type = 'application/json' | 98 response.content_type = 'application/json' |
103 | 99 |
104 environ = state.request.environ | 100 environ = state.request.environ |
105 start = time.time() | 101 start = time.time() |
106 ip_addr = self._get_ip_addr(environ) | 102 ip_addr = get_ip_addr(environ) |
107 self._req_id = None | 103 self._req_id = None |
108 if 'CONTENT_LENGTH' not in environ: | 104 if 'CONTENT_LENGTH' not in environ: |
109 log.debug("No Content-Length") | 105 log.debug("No Content-Length") |
110 raise JSONRPCErrorResponse(retid=self._req_id, | 106 raise JSONRPCErrorResponse(retid=self._req_id, |
111 message="No Content-Length in request") | 107 message="No Content-Length in request") |
206 self._rpc_args.update(self._request_params) | 202 self._rpc_args.update(self._request_params) |
207 self._rpc_args['action'] = self._req_method | 203 self._rpc_args['action'] = self._req_method |
208 self._rpc_args['environ'] = environ | 204 self._rpc_args['environ'] = environ |
209 | 205 |
210 log.info('IP: %s Request to %s time: %.3fs' % ( | 206 log.info('IP: %s Request to %s time: %.3fs' % ( |
211 self._get_ip_addr(environ), | 207 get_ip_addr(environ), |
212 get_path_info(environ), time.time() - start) | 208 get_path_info(environ), time.time() - start) |
213 ) | 209 ) |
214 | 210 |
215 state.set_action(self._rpc_call, []) | 211 state.set_action(self._rpc_call, []) |
216 state.set_params(self._rpc_args) | 212 state.set_params(self._rpc_args) |