Commit 5bad72cb authored by Antoine Millet's avatar Antoine Millet
Browse files

Implemented right rules evaluation optimization

Do not use the TQL DB when the matching is done on the "a" tag.
parent 8890b9ab
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
"""

import os
import re
from fnmatch import fnmatch as glob

from sjrpc.server import SSLRpcServer
@@ -48,6 +49,9 @@ import cloudcontrol.server.clients.bootstrap
import cloudcontrol.server.clients.spv


RE_FAST_RULE_MATCHING = re.compile('^a=([a-zA-Z0-9_-]+)$')


class WelcomeHandler(RpcHandler):
    """ Default handler used on client connections of the server.
    """
@@ -287,7 +291,10 @@ class CCServer(object):
        deny_rules = []
        for rule in self.rights.iter_rules_method(method):
            # Is the rule matching the requester object:
            if requester not in self.db.raw_query(rule.match):
            match = RE_FAST_RULE_MATCHING.match(rule.match)
            if match and match.group(1) != requester:
                continue
            elif requester not in self.db.raw_query(rule.match):
                continue
            if rule.action == rule.ACCEPT:
                allowed_result |= tql_response & self.db.raw_query(rule.tql)
@@ -315,7 +322,10 @@ class CCServer(object):
        """
        ok = False  # Default policy is to reject
        for rule in self.rights.iter_rules_method(method):
            if requester not in self.db.raw_query(rule.match):
            match = RE_FAST_RULE_MATCHING.match(rule.match)
            if match and match.group(1) != requester:
                continue
            elif requester not in self.db.raw_query(rule.match):
                continue
            if rule.action == rule.ACCEPT:
                ok = True