diff --git a/conf/attributes.yml b/conf/attributes.yml index f28408b..d6feeec 100644 --- a/conf/attributes.yml +++ b/conf/attributes.yml @@ -96,7 +96,7 @@ home: ad: Home password: - decription: "Password of the user" + description: "Password of the user" display_name: "Password" self: True type: password @@ -104,6 +104,8 @@ password: ldap: userPassword ad: userPassword logscript: + description: "Windows login script" + display_name: "Login script" type: fix value: login1.bat backend-attributes: diff --git a/ldapcherry/attributes.py b/ldapcherry/attributes.py index 1047625..88940e5 100644 --- a/ldapcherry/attributes.py +++ b/ldapcherry/attributes.py @@ -10,7 +10,7 @@ import sys from ldapcherry.pyyamlwrapper import loadNoDump from ldapcherry.pyyamlwrapper import DumplicatedKey -from ldapcherry.exceptions import MissingAttributesFile +from ldapcherry.exceptions import MissingAttributesFile, MissingKey from sets import Set import yaml @@ -30,6 +30,14 @@ class Attributes: except DumplicatedKey as e: raise DumplicateAttributesKey(e.key) + for attrid in self.attributes: + self._mandatory_check(attrid) + + def _mandatory_check(self, attr): + for m in ['description', 'display_name', 'type', 'backend-attributes']: + if m not in self.attributes[attr]: + raise MissingKey(m, attr, self.attributes_file) + def get_selfattributes(self): """get the list of groups from roles""" pass diff --git a/tests/cfg/attributes_missing_mandatory.yml b/tests/cfg/attributes_missing_mandatory.yml new file mode 100644 index 0000000..1d86cb1 --- /dev/null +++ b/tests/cfg/attributes_missing_mandatory.yml @@ -0,0 +1,111 @@ +cn: + description: "Firt Name and Display Name" + display_name: "Display Name" + type: string + autofill: + function: cn + args: + - $first-name + - $name + backend-attributes: + ldap: cn + ad: CN +first-name: + description: "First name of the user" + display_name: "First Name" + type: string + backend-attributes: + ldap: givenName + ad: givenName +name: + description: "Family name of the user" + display_name: "Name" + type: string + backend-attributes: + ldap: sn + ad: sn +email: + description: "Email of the user" + display_name: "Name" + type: email + autofill: + function: email + args: + - $first-name + - $last-name + - '@example.com' + backend-attributes: + ldap: email + ad: EMAIL +uid: + display_name: "UID" + type: string + autofill: + function: uid + args: + - $first-name + - $last-name + backend-attributes: + ldap: uid + ad: UID +uidNumber: + description: "User ID Number of the user" + display_name: "UID Number" + type: int + autofill: + function: uidNumber + args: + - $first-name + - $last-name + backend-attributes: + ldap: uidNumber + ad: UIDNumber +gidNumber: + description: "Group ID Number of the user" + display_name: "GID Number" + type: int + default: 10000 + backend-attributes: + ldap: gidNumber + ad: GIDNumber +shell: + description: "Shell of the user" + display_name: "Shell" + self: True + type: stringlist + values: + - /bin/bash + - /bin/zsh + - /bin/sh + backend-attributes: + ldap: shell + ad: SHELL +home: + description: "Home user path" + display_name: "Home" + type: string + autofill: + function: home + args: + - $first-name + - $last-name + - /home/ + backend-attributes: + ldap: home + ad: Home + +password: + description: "Password of the user" + display_name: "Password" + self: True + type: password + backend-attributes: + ldap: userPassword + ad: userPassword +logscript: + description: "Windows login script" + display_name: "Login script" + type: fix + value: login1.bat + backend-attributes: + ad: logonScript diff --git a/tests/test_Attributes.py b/tests/test_Attributes.py index 53739ef..5d3599d 100644 --- a/tests/test_Attributes.py +++ b/tests/test_Attributes.py @@ -8,7 +8,7 @@ import pytest import sys from sets import Set from ldapcherry.attributes import Attributes -from ldapcherry.exceptions import MissingAttributesFile +from ldapcherry.exceptions import MissingAttributesFile, MissingKey from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError class TestError(object): @@ -25,14 +25,14 @@ class TestError(object): else: raise AssertionError("expected an exception") -# def testMissingDisplayName(self): -# try: -# inv = Attributes('./tests/cfg/attributes_missing_diplay_name.yml') -# except MissingKey: -# return -# else: -# raise AssertionError("expected an exception") -# + def testMissingMandatory(self): + try: + inv = Attributes('./tests/cfg/attributes_missing_mandatory.yml') + except MissingKey: + return + else: + raise AssertionError("expected an exception") + # def testAttrKeyDuplication(self): # try: # inv = Attributes('./tests/cfg/attributes_key_dup.yml')