Loading ccserver/handlers.py +73 −26 Original line number Diff line number Diff line Loading @@ -6,7 +6,8 @@ import logging from sjrpc.utils import RpcHandler, pure from conf import CCConf from exceptions import (AlreadyRegistered, AuthenticationError, RightError, ReservedTagError) ReservedTagError, BadObjectError, NotConnectedAccountError) def listed(func): func.__listed__ = True Loading Loading @@ -134,12 +135,17 @@ class ClientHandler(OnlineCCHandler): ''' objects = self._server.list(query) errs = Reporter() with self._server.conf: for obj in objects: if 'a' not in obj: raise BadObjectError('All objects must have the "a" tag.') for obj in objects: errs.error(obj['id'], 'not an account') continue self._server.conf.set_password(obj['a'], password, method) return errs.get_dict() @listed def addaccount(self, conn, login, role, password=None): ''' Loading Loading @@ -221,11 +227,20 @@ class ClientHandler(OnlineCCHandler): ''' objects = self._server.list(query) errs = Reporter() with self._server.conf: for obj in objects: if 'a' not in obj: raise BadObjectError('All objects must have the "a" tag.') for obj in objects: errs.error(obj['id'], 'not an account') continue try: self._server.conf.remove_account(obj['a']) except CCConf.UnknownAccount: errs.error(obj['id'], 'unknown account') else: errs.success(obj['id'], 'account deleted') return errs.get_dict() @listed def close(self, conn, query): Loading Loading @@ -278,11 +293,21 @@ class ClientHandler(OnlineCCHandler): ''' objects = self._server.list(query) errs = Reporter() with self._server.conf: for obj in objects: print obj if 'a' not in obj: raise BadObjectError('All objects must have the "a" tag.') for obj in objects: errs.error(obj['id'], 'not an account') continue try: self._server.kill(obj['a']) except NotConnectedAccountError: errs.error(obj['id'], 'account is not connected') else: errs.success(obj['id'], 'account killed') return errs.get_dict() @listed def rights(self, conn, query): Loading @@ -307,11 +332,21 @@ class ClientHandler(OnlineCCHandler): ''' objects = self._server.list(query) errs = Reporter() with self._server.conf: for obj in objects: if 'a' not in obj: raise BadObjectError('All objects must have the "a" tag.') for obj in objects: self._server.conf.add_right(obj['a'], tql, method, allow, index) errs.error(obj['id'], 'not an account') continue try: self._server.conf.add_right(obj['a'], tql, method, allow, index) except conf.UnknownAccount: errs.error(obj['id'], 'unknown account') else: errs.success(obj['id'], 'right rule added') return errs.get_dict() @listed def delright(self, conn, query, index): Loading @@ -320,11 +355,23 @@ class ClientHandler(OnlineCCHandler): ''' objects = self._server.list(query) errs = Reporter() with self._server.conf: for obj in objects: if 'a' not in obj: raise BadObjectError('All objects must have the "a" tag.') for obj in objects: errs.error(obj['id'], 'not an account') continue try: self._server.conf.remove_right(obj['a'], index) except conf.UnknownAccount: errs.error(obj['id'], 'unknown account') except conf.OutOfRangeIndexError: errs.error(obj['id'], 'index out of range') else: errs.success(obj['id'], 'right rule deleted') return errs.get_dict() def proxy_client(self, conn, login, command, *args, **kwargs): client = self._server.get_connection(login) Loading Loading
ccserver/handlers.py +73 −26 Original line number Diff line number Diff line Loading @@ -6,7 +6,8 @@ import logging from sjrpc.utils import RpcHandler, pure from conf import CCConf from exceptions import (AlreadyRegistered, AuthenticationError, RightError, ReservedTagError) ReservedTagError, BadObjectError, NotConnectedAccountError) def listed(func): func.__listed__ = True Loading Loading @@ -134,12 +135,17 @@ class ClientHandler(OnlineCCHandler): ''' objects = self._server.list(query) errs = Reporter() with self._server.conf: for obj in objects: if 'a' not in obj: raise BadObjectError('All objects must have the "a" tag.') for obj in objects: errs.error(obj['id'], 'not an account') continue self._server.conf.set_password(obj['a'], password, method) return errs.get_dict() @listed def addaccount(self, conn, login, role, password=None): ''' Loading Loading @@ -221,11 +227,20 @@ class ClientHandler(OnlineCCHandler): ''' objects = self._server.list(query) errs = Reporter() with self._server.conf: for obj in objects: if 'a' not in obj: raise BadObjectError('All objects must have the "a" tag.') for obj in objects: errs.error(obj['id'], 'not an account') continue try: self._server.conf.remove_account(obj['a']) except CCConf.UnknownAccount: errs.error(obj['id'], 'unknown account') else: errs.success(obj['id'], 'account deleted') return errs.get_dict() @listed def close(self, conn, query): Loading Loading @@ -278,11 +293,21 @@ class ClientHandler(OnlineCCHandler): ''' objects = self._server.list(query) errs = Reporter() with self._server.conf: for obj in objects: print obj if 'a' not in obj: raise BadObjectError('All objects must have the "a" tag.') for obj in objects: errs.error(obj['id'], 'not an account') continue try: self._server.kill(obj['a']) except NotConnectedAccountError: errs.error(obj['id'], 'account is not connected') else: errs.success(obj['id'], 'account killed') return errs.get_dict() @listed def rights(self, conn, query): Loading @@ -307,11 +332,21 @@ class ClientHandler(OnlineCCHandler): ''' objects = self._server.list(query) errs = Reporter() with self._server.conf: for obj in objects: if 'a' not in obj: raise BadObjectError('All objects must have the "a" tag.') for obj in objects: self._server.conf.add_right(obj['a'], tql, method, allow, index) errs.error(obj['id'], 'not an account') continue try: self._server.conf.add_right(obj['a'], tql, method, allow, index) except conf.UnknownAccount: errs.error(obj['id'], 'unknown account') else: errs.success(obj['id'], 'right rule added') return errs.get_dict() @listed def delright(self, conn, query, index): Loading @@ -320,11 +355,23 @@ class ClientHandler(OnlineCCHandler): ''' objects = self._server.list(query) errs = Reporter() with self._server.conf: for obj in objects: if 'a' not in obj: raise BadObjectError('All objects must have the "a" tag.') for obj in objects: errs.error(obj['id'], 'not an account') continue try: self._server.conf.remove_right(obj['a'], index) except conf.UnknownAccount: errs.error(obj['id'], 'unknown account') except conf.OutOfRangeIndexError: errs.error(obj['id'], 'index out of range') else: errs.success(obj['id'], 'right rule deleted') return errs.get_dict() def proxy_client(self, conn, login, command, *args, **kwargs): client = self._server.get_connection(login) Loading