Esempio n. 1
0
    def _read_policy_file(self):
        """Read contents of the policy file

        This re-caches policy data if the file has been changed.
        """
        mtime = os.path.getmtime(self.policy_path)
        if not self.policy_file_contents or mtime != self.policy_file_mtime:
            LOG.debug(_("Loading policy from %s") % self.policy_path)
            with open(self.policy_path) as fap:
                raw_contents = fap.read()
                rules_dict = json.loads(raw_contents)
                self.policy_file_contents = dict((k, policy.parse_rule(v)) for k, v in rules_dict.items())
            self.policy_file_mtime = mtime
        return self.policy_file_contents
Esempio n. 2
0
    def _read_policy_file(self):
        """Read contents of the policy file

        This re-caches policy data if the file has been changed.
        """
        mtime = os.path.getmtime(self.policy_path)
        if not self.policy_file_contents or mtime != self.policy_file_mtime:
            LOG.debug(_("Loading policy from %s") % self.policy_path)
            with open(self.policy_path) as fap:
                raw_contents = fap.read()
                rules_dict = json.loads(raw_contents)
                self.policy_file_contents = dict(
                    (k, policy.parse_rule(v)) for k, v in rules_dict.items())
            self.policy_file_mtime = mtime
        return self.policy_file_contents
 def _enforcer_from_rules(self, unparsed_rules):
     rules = dict((k, policy.parse_rule(v))
                  for (k, v) in unparsed_rules.items())
     enforcer = glance.api.policy.Enforcer()
     enforcer.set_rules(rules, overwrite=True)
     return enforcer