def CheckAccess(self, subject, token):
    subject = rdfvalue.RDFURN(subject)
    subject_str = subject.SerializeToString()

    for check_tuple in self.checks:
      regex_text, regex, require, require_args, require_kwargs = check_tuple

      match = regex.match(subject_str)
      if not match:
        continue

      if require:
        # If require() fails, it raises access_control.UnauthorizedAccess.
        require(subject, token, *require_args, **require_kwargs)

      logging.debug(u"Datastore access granted to %s on %s by pattern: %s "
                    u"with reason: %s (require=%s, require_args=%s, "
                    u"require_kwargs=%s, helper_name=%s)",
                    utils.SmartUnicode(token.username),
                    utils.SmartUnicode(subject_str),
                    utils.SmartUnicode(regex_text),
                    utils.SmartUnicode(token.reason),
                    require, require_args, require_kwargs, self.helper_name)
      return True

    logging.warn("Datastore access denied to %s (no matched rules)",
                 subject_str)
    raise access_control.UnauthorizedAccess(
        "Access to %s rejected: (no matched rules)." % subject, subject=subject)
Test get primary key, compound key.
dataset/ETHPy150Open google/grr/grr/lib/aff4_objects/user_managers.py/CheckAccessHelper.CheckAccess--crossover with--dataset/ETHPy150Open GeoscienceAustralia/agdc/tests/test_dbcompare.py/TestComparisonWrapper.test_primary_key_compound