Ejemplo n.º 1
0
    def _rule(self, rule_name, helper):
        if (rule_name, helper) not in self.rules:
            rule_path = os.path.join(self.csr_data_dir, 'rules',
                                     '%s.json' % rule_name)
            try:
                with open(rule_path) as rule_file:
                    ruleset = json.load(rule_file)
            except IOError:
                raise errors.NotFound(
                    reason=_('Ruleset %(ruleset)s does not exist.') %
                    {'ruleset': rule_name})

            matching_rules = [r for r in ruleset['rules']
                              if r['helper'] == helper]
            if len(matching_rules) == 0:
                raise errors.EmptyResult(
                    reason=_('No transformation in "%(ruleset)s" rule supports'
                             ' helper "%(helper)s"') %
                    {'ruleset': rule_name, 'helper': helper})
            elif len(matching_rules) > 1:
                raise errors.RedundantMappingRule(
                    ruleset=rule_name, helper=helper)
            rule = matching_rules[0]

            options = {}
            if 'options' in ruleset:
                options.update(ruleset['options'])
            if 'options' in rule:
                options.update(rule['options'])

            self.rules[(rule_name, helper)] = Rule(
                rule_name, rule['template'], options)

        return self.rules[(rule_name, helper)]
Ejemplo n.º 2
0
    def exc_callback(self, args, options, exc, call_func, *call_args,
                     **call_kwargs):
        if call_func.__name__ == 'find_entries':
            if isinstance(exc, errors.NotFound):
                # ignore missing containers since they will be created
                # automatically on vault creation.
                raise errors.EmptyResult(reason=str(exc))

        raise exc
Ejemplo n.º 3
0
 def get_entries(self,
                 base_dn,
                 scope=SCOPE_SUBTREE,
                 filter=None,
                 attrs_list=None,
                 get_effective_rights=False,
                 **kwargs):
     if self.results is None:
         raise errors.EmptyResult(reason='no matching entry found')
     return self.results
Ejemplo n.º 4
0
    def _rule(self, rule_name):
        if rule_name not in self.rules:
            try:
                with self._open('rules', '%s.json' % rule_name) as f:
                    ruleconf = json.load(f)
            except IOError:
                raise errors.NotFound(
                    reason=_('No generation rule %(rulename)s found.') %
                    {'rulename': rule_name})

            try:
                rule = ruleconf['rule']
            except KeyError:
                raise errors.EmptyResult(
                    reason=_('Generation rule "%(rulename)s" is missing the'
                             ' "rule" key') % {'rulename': rule_name})

            options = ruleconf.get('options', {})

            self.rules[rule_name] = Rule(rule_name, rule['template'], options)

        return self.rules[rule_name]