diff options
author | Marcin Kuzminski <marcin@python-works.com> | 2012-12-31 01:51:30 +0100 |
---|---|---|
committer | Marcin Kuzminski <marcin@python-works.com> | 2012-12-31 01:51:30 +0100 |
commit | d1a2718270cb54f779332f686344731c121b3725 (patch) | |
tree | 83ebfc780ce09f21b23b2ea80cefdb804738e340 | |
parent | b8e1df75b21aad11a161aa3930eb7f26c1c45770 (diff) |
added API method for checking IP
--HG--
branch : beta
-rw-r--r-- | docs/api/api.rst | 35 | ||||
-rw-r--r-- | rhodecode/controllers/api/__init__.py | 5 | ||||
-rw-r--r-- | rhodecode/controllers/api/api.py | 21 |
3 files changed, 55 insertions, 6 deletions
diff --git a/docs/api/api.rst b/docs/api/api.rst index e4a27137..fc40d2b3 100644 --- a/docs/api/api.rst +++ b/docs/api/api.rst @@ -168,7 +168,6 @@ INPUT:: "repoid" : "<reponame or repo_id>" "userid" : "<user_id or username>", "locked" : "<bool true|false>" - } OUTPUT:: @@ -178,6 +177,40 @@ OUTPUT:: error : null +show_ip +------- + +Shows IP address as seen from RhodeCode server, together with all +defined IP addresses for given user. +This command can be executed only using api_key belonging to user with admin +rights. + +INPUT:: + + id : <id_for_response> + api_key : "<api_key>" + method : "show_ip" + args : { + "userid" : "<user_id or username>", + } + +OUTPUT:: + + id : <id_given_in_input> + result : { + "ip_addr_server": <ip_from_clien>", + "user_ips": [ + { + "ip_addr": "<ip_with_mask>", + "ip_range": ["<start_ip>", "<end_ip>"], + }, + ... + ] + } + + error : null + + get_user -------- diff --git a/rhodecode/controllers/api/__init__.py b/rhodecode/controllers/api/__init__.py index 01cfe118..6dcc79b2 100644 --- a/rhodecode/controllers/api/__init__.py +++ b/rhodecode/controllers/api/__init__.py @@ -86,6 +86,9 @@ class JSONRPCController(WSGIController): """ + def _get_ip_addr(self, environ): + return _get_ip_addr(environ) + def _get_method_args(self): """ Return `self._rpc_args` to dispatched controller method @@ -99,7 +102,7 @@ class JSONRPCController(WSGIController): controller and if it exists, dispatch to it. """ start = time.time() - ip_addr = self._get_ip_addr(environ) + ip_addr = self.ip_addr = self._get_ip_addr(environ) self._req_id = None if 'CONTENT_LENGTH' not in environ: log.debug("No Content-Length") diff --git a/rhodecode/controllers/api/api.py b/rhodecode/controllers/api/api.py index c3b31c58..4176ee8c 100644 --- a/rhodecode/controllers/api/api.py +++ b/rhodecode/controllers/api/api.py @@ -38,7 +38,7 @@ from rhodecode.model.repo import RepoModel from rhodecode.model.user import UserModel from rhodecode.model.users_group import UsersGroupModel from rhodecode.model.permission import PermissionModel -from rhodecode.model.db import Repository, RhodeCodeSetting +from rhodecode.model.db import Repository, RhodeCodeSetting, UserIpMap log = logging.getLogger(__name__) @@ -140,9 +140,6 @@ class ApiController(JSONRPCController): errors that happens """ - def _get_ip_addr(self, environ): - from rhodecode.lib.base import _get_ip_addr - return _get_ip_addr(environ) @HasPermissionAllDecorator('hg.admin') def pull(self, apiuser, repoid): @@ -215,6 +212,22 @@ class ApiController(JSONRPCController): ) @HasPermissionAllDecorator('hg.admin') + def show_ip(self, apiuser, userid): + """ + Shows IP address as seen from RhodeCode server, together with all + defined IP addresses for given user + + :param apiuser: + :param userid: + """ + user = get_user_or_error(userid) + ips = UserIpMap.query().filter(UserIpMap.user == user).all() + return dict( + ip_addr_server=self.ip_addr, + user_ips=ips + ) + + @HasPermissionAllDecorator('hg.admin') def get_user(self, apiuser, userid): """" Get a user by username |