mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-22 01:14:21 +01:00
adding key and fixing unit tests
This commit is contained in:
parent
8d8f4ffbe5
commit
2860f5af6c
@ -10,7 +10,7 @@ import sys
|
||||
|
||||
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 @@ class Attributes:
|
||||
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 @@ class Attributes:
|
||||
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']:
|
||||
|
@ -79,6 +79,16 @@ class WrongParamValue(Exception):
|
||||
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
|
||||
|
@ -2,6 +2,7 @@ cn:
|
||||
description: "Firt Name and Display Name"
|
||||
display_name: "Display Name"
|
||||
type: string
|
||||
search_displayed: True
|
||||
autofill:
|
||||
function: cn
|
||||
args:
|
||||
@ -13,6 +14,7 @@ cn:
|
||||
first-name:
|
||||
description: "First name of the user"
|
||||
display_name: "First Name"
|
||||
search_displayed: True
|
||||
type: string
|
||||
backends:
|
||||
ldap: givenName
|
||||
@ -20,6 +22,7 @@ first-name:
|
||||
name:
|
||||
description: "Family name of the user"
|
||||
display_name: "Name"
|
||||
search_displayed: True
|
||||
type: string
|
||||
backends:
|
||||
ldap: sn
|
||||
@ -27,6 +30,7 @@ name:
|
||||
email:
|
||||
description: "Email of the user"
|
||||
display_name: "Name"
|
||||
search_displayed: True
|
||||
type: email
|
||||
autofill:
|
||||
function: email
|
||||
@ -40,6 +44,8 @@ email:
|
||||
uid:
|
||||
description: "UID of the user"
|
||||
display_name: "UID"
|
||||
search_displayed: True
|
||||
key: True
|
||||
type: string
|
||||
autofill:
|
||||
function: uid
|
||||
|
@ -40,6 +40,7 @@ email:
|
||||
uid:
|
||||
display_name: "UID"
|
||||
type: string
|
||||
key: True
|
||||
autofill:
|
||||
function: uid
|
||||
args:
|
||||
|
@ -2,6 +2,7 @@ cn:
|
||||
description: "Firt Name and Display Name"
|
||||
display_name: "Display Name"
|
||||
type: notatype
|
||||
key: True
|
||||
autofill:
|
||||
function: cn
|
||||
args:
|
||||
|
Loading…
Reference in New Issue
Block a user