diff --git a/ldapcherry/attributes.py b/ldapcherry/attributes.py index cfea209..af894e6 100644 --- a/ldapcherry/attributes.py +++ b/ldapcherry/attributes.py @@ -10,7 +10,7 @@ from ldapcherry.pyyamlwrapper import loadNoDump from ldapcherry.pyyamlwrapper import DumplicatedKey -from ldapcherry.exceptions import MissingAttributesFile, MissingKey, WrongAttributeType, WrongBackend +from ldapcherry.exceptions import MissingAttributesFile, MissingKey, WrongAttributeType, WrongBackend, DumplicateUserKey, MissingUserKey from sets import Set import yaml @@ -23,6 +23,8 @@ self.backends = Set([]) self.self_attributes = Set([]) self.backend_attributes = {} + self.displayed_attributes = [] + self.key = None try: stream = open(attributes_file, 'r') except: @@ -39,11 +41,26 @@ raise WrongAttributeType(attr['type'], attrid, attributes_file) if 'self' in attr and attr['self']: self.self_attributes.add(attrid) + if 'key' in attr and attr['key']: + if not self.key is None: + raise DumplicateUserKey(attrid, self.key) + self.key = attrid for b in attr['backends']: self.backends.add(b) if b not in self.backend_attributes: self.backend_attributes[b] = [] self.backend_attributes[b].append(attr['backends'][b]) + if 'search_displayed' in attr and attr['search_displayed']: + self.displayed_attributes.append(attrid) + + if self.key is None: + raise MissingUserKey() + + def get_search_attributes(self): + return self.displayed_attributes + + def get_key(self): + return self.key def _mandatory_check(self, attr): for m in ['description', 'display_name', 'type', 'backends']: diff --git a/ldapcherry/exceptions.py b/ldapcherry/exceptions.py index 27d62b4..4932725 100644 --- a/ldapcherry/exceptions.py +++ b/ldapcherry/exceptions.py @@ -79,6 +79,16 @@ possible_values_str = string.join(possible_values, ', ') self.log = "wrong value for param <%(param)s> in section <%(section)s>, possible values are [%(values)s]" % {'param': param, 'section': section, 'values': possible_values_str} +class DumplicateUserKey(Exception): + def __init__(self, attrid1, attrid2): + self.attrid1 = attrid1 + self.attrid2 = attrid2 + self.log = "duplicate key in <%(attrid1)s> and <%(attrid2)s>" % {'attrid1': attrid1, 'attrid2': attrid2} + +class MissingUserKey(Exception): + def __init__(self): + self.log = "missing key" + class WrongAttributeType(Exception): def __init__(self, key, section, ymlfile): self.key = key diff --git a/tests/cfg/attributes.yml b/tests/cfg/attributes.yml index 5f5ebaf..834b851 100644 --- a/tests/cfg/attributes.yml +++ b/tests/cfg/attributes.yml @@ -2,6 +2,7 @@ description: "Firt Name and Display Name" display_name: "Display Name" type: string + search_displayed: True autofill: function: cn args: @@ -13,6 +14,7 @@ first-name: description: "First name of the user" display_name: "First Name" + search_displayed: True type: string backends: ldap: givenName @@ -20,6 +22,7 @@ name: description: "Family name of the user" display_name: "Name" + search_displayed: True type: string backends: ldap: sn @@ -27,6 +30,7 @@ email: description: "Email of the user" display_name: "Name" + search_displayed: True type: email autofill: function: email @@ -40,6 +44,8 @@ uid: description: "UID of the user" display_name: "UID" + search_displayed: True + key: True type: string autofill: function: uid diff --git a/tests/cfg/attributes_missing_mandatory.yml b/tests/cfg/attributes_missing_mandatory.yml index 07729df..1ffbc45 100644 --- a/tests/cfg/attributes_missing_mandatory.yml +++ b/tests/cfg/attributes_missing_mandatory.yml @@ -40,6 +40,7 @@ uid: display_name: "UID" type: string + key: True autofill: function: uid args: diff --git a/tests/cfg/attributes_wrong_type.yml b/tests/cfg/attributes_wrong_type.yml index 9a5bc71..4a276a9 100644 --- a/tests/cfg/attributes_wrong_type.yml +++ b/tests/cfg/attributes_wrong_type.yml @@ -2,6 +2,7 @@ description: "Firt Name and Display Name" display_name: "Display Name" type: notatype + key: True autofill: function: cn args: