Commit 051f0575 authored by Antoine Millet's avatar Antoine Millet
Browse files

Added right rules management.

parent 78db68d6
Loading
Loading
Loading
Loading
+48 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ class CCConf(object):
    CONF_TEMPLATE = {'password': None,
                     'role': None,
                     'tags': {},
                     'perms': None}
                     'rights': []}

    RE_SALTPW = re.compile(r'{(?P<method>[A-Z]+)}(?P<password>.+)')

@@ -297,6 +297,48 @@ class CCConf(object):
                conf['password'] = self._hash_password(password)
            self._set_conf(login, conf, create=True)

    @_writer
    def add_right(self, login, tql, method=None, allow=True, index=None):
        '''
        Add a right rule to the provided account.

        :param login: the login of the account
        :param tql: the TQL request to allow
        :param method: the method to which apply the right, None if all
        :param allow: True if the rules allow the call, or False if it deny.
        :param index: the index of the new rule, set None if the rule is
            appended to the end of the ruleset.

        .. note::
           If the index is out of range, the rule will be added to the end of
           the ruleset.
        '''

        conf = self._get_conf(login)
        rights = conf['rights']
        rule = {'tql': tql, 'method': method, 'allow': allow}
        if index is None:
            index = len(rights)
        rights.insert(index, rule)
        self._set_conf(login, conf)

    @_writer
    def remove_right(self, login, index):
        '''
        Remove a right rule from the provided account.

        :param login: the login of the account
        :param index: the index of the rule to delete
        '''

        conf = self._get_conf(login)
        rights = conf['rights']
        try:
            rights.pop(index)
        except IndexError:
            raise CCConf.OutOfRangeIndexError('Bad rule index %s' % repr(index))
        self._set_conf(login, conf)

    def list_accounts(self):
        '''
        List all registered accounts.
@@ -321,5 +363,10 @@ class CCConf(object):
    class AlreadyExistingAccount(Exception):
        pass


    class BadMethodError(Exception):
        pass


    class OutOfRangeIndexError(Exception):
        pass
+15 −0
Original line number Diff line number Diff line
@@ -158,6 +158,21 @@ class ClientHandler(OnlineCCHandler):
        '''
        self._server.conf.remove_account(login)

    @pure
    @listed
    def rights(self, login):
        return self._server.conf.show(login)['rights']

    @pure
    @listed
    def addright(self, login, tql, method=None, allow=True, index=None):
        self._server.conf.add_right(login, tql, method, allow, index)

    @pure
    @listed
    def delright(self, login, index):
        self._server.conf.remove_right(login, index)

    @pure
    def proxy_client(self, login, command, *args, **kwargs):
        client = self._server.get_connection(login)