def get_matchingrules(self): """Return a list of the server defined matching rules""" attrs = ['matchingrules'] results = self.conn.search_s(DN_SCHEMA, ldap.SCOPE_BASE, 'objectclass=*', attrs)[0] matchingRules = [ MatchingRule(mr) for mr in results.getValues('matchingRules') ] return matchingRules
def get_matchingrules(self, json=False): """Return a list of the server defined matching rules""" attrs = ['matchingrules'] results = self.conn.search_s(DN_SCHEMA, ldap.SCOPE_BASE, 'objectclass=*', attrs)[0] if json: matchingRules = [vars(MatchingRule(mr)) for mr in results.getValues('matchingRules')] for mr in matchingRules: # Add normalized name for sorting if mr['names']: mr['name'] = mr['names'][0].lower() else: mr['name'] = "" matchingRules = sorted(matchingRules, key=itemgetter('name')) result = {'type': 'list', 'items': matchingRules} return dump_json(result) else: matchingRules = [MatchingRule(mr) for mr in results.getValues('matchingRules')] return matchingRules