mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-22 09:24: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 loadNoDump
|
||||||
from ldapcherry.pyyamlwrapper import DumplicatedKey
|
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
|
from sets import Set
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
@ -23,6 +23,8 @@ class Attributes:
|
|||||||
self.backends = Set([])
|
self.backends = Set([])
|
||||||
self.self_attributes = Set([])
|
self.self_attributes = Set([])
|
||||||
self.backend_attributes = {}
|
self.backend_attributes = {}
|
||||||
|
self.displayed_attributes = []
|
||||||
|
self.key = None
|
||||||
try:
|
try:
|
||||||
stream = open(attributes_file, 'r')
|
stream = open(attributes_file, 'r')
|
||||||
except:
|
except:
|
||||||
@ -39,11 +41,26 @@ class Attributes:
|
|||||||
raise WrongAttributeType(attr['type'], attrid, attributes_file)
|
raise WrongAttributeType(attr['type'], attrid, attributes_file)
|
||||||
if 'self' in attr and attr['self']:
|
if 'self' in attr and attr['self']:
|
||||||
self.self_attributes.add(attrid)
|
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']:
|
for b in attr['backends']:
|
||||||
self.backends.add(b)
|
self.backends.add(b)
|
||||||
if b not in self.backend_attributes:
|
if b not in self.backend_attributes:
|
||||||
self.backend_attributes[b] = []
|
self.backend_attributes[b] = []
|
||||||
self.backend_attributes[b].append(attr['backends'][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):
|
def _mandatory_check(self, attr):
|
||||||
for m in ['description', 'display_name', 'type', 'backends']:
|
for m in ['description', 'display_name', 'type', 'backends']:
|
||||||
|
@ -79,6 +79,16 @@ class WrongParamValue(Exception):
|
|||||||
possible_values_str = string.join(possible_values, ', ')
|
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}
|
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):
|
class WrongAttributeType(Exception):
|
||||||
def __init__(self, key, section, ymlfile):
|
def __init__(self, key, section, ymlfile):
|
||||||
self.key = key
|
self.key = key
|
||||||
|
@ -2,6 +2,7 @@ cn:
|
|||||||
description: "Firt Name and Display Name"
|
description: "Firt Name and Display Name"
|
||||||
display_name: "Display Name"
|
display_name: "Display Name"
|
||||||
type: string
|
type: string
|
||||||
|
search_displayed: True
|
||||||
autofill:
|
autofill:
|
||||||
function: cn
|
function: cn
|
||||||
args:
|
args:
|
||||||
@ -13,6 +14,7 @@ cn:
|
|||||||
first-name:
|
first-name:
|
||||||
description: "First name of the user"
|
description: "First name of the user"
|
||||||
display_name: "First Name"
|
display_name: "First Name"
|
||||||
|
search_displayed: True
|
||||||
type: string
|
type: string
|
||||||
backends:
|
backends:
|
||||||
ldap: givenName
|
ldap: givenName
|
||||||
@ -20,6 +22,7 @@ first-name:
|
|||||||
name:
|
name:
|
||||||
description: "Family name of the user"
|
description: "Family name of the user"
|
||||||
display_name: "Name"
|
display_name: "Name"
|
||||||
|
search_displayed: True
|
||||||
type: string
|
type: string
|
||||||
backends:
|
backends:
|
||||||
ldap: sn
|
ldap: sn
|
||||||
@ -27,6 +30,7 @@ name:
|
|||||||
email:
|
email:
|
||||||
description: "Email of the user"
|
description: "Email of the user"
|
||||||
display_name: "Name"
|
display_name: "Name"
|
||||||
|
search_displayed: True
|
||||||
type: email
|
type: email
|
||||||
autofill:
|
autofill:
|
||||||
function: email
|
function: email
|
||||||
@ -40,6 +44,8 @@ email:
|
|||||||
uid:
|
uid:
|
||||||
description: "UID of the user"
|
description: "UID of the user"
|
||||||
display_name: "UID"
|
display_name: "UID"
|
||||||
|
search_displayed: True
|
||||||
|
key: True
|
||||||
type: string
|
type: string
|
||||||
autofill:
|
autofill:
|
||||||
function: uid
|
function: uid
|
||||||
|
@ -40,6 +40,7 @@ email:
|
|||||||
uid:
|
uid:
|
||||||
display_name: "UID"
|
display_name: "UID"
|
||||||
type: string
|
type: string
|
||||||
|
key: True
|
||||||
autofill:
|
autofill:
|
||||||
function: uid
|
function: uid
|
||||||
args:
|
args:
|
||||||
|
@ -2,6 +2,7 @@ cn:
|
|||||||
description: "Firt Name and Display Name"
|
description: "Firt Name and Display Name"
|
||||||
display_name: "Display Name"
|
display_name: "Display Name"
|
||||||
type: notatype
|
type: notatype
|
||||||
|
key: True
|
||||||
autofill:
|
autofill:
|
||||||
function: cn
|
function: cn
|
||||||
args:
|
args:
|
||||||
|
Loading…
Reference in New Issue
Block a user