1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-06-01 16:48:06 +02:00

adding checks for mandatory elements of attributes.yml

This commit is contained in:
kakwa 2015-05-17 19:22:11 +02:00
parent dbc88163dd
commit 679c2bba85
4 changed files with 132 additions and 11 deletions

View File

@ -96,7 +96,7 @@ home:
ad: Home ad: Home
password: password:
decription: "Password of the user" description: "Password of the user"
display_name: "Password" display_name: "Password"
self: True self: True
type: password type: password
@ -104,6 +104,8 @@ password:
ldap: userPassword ldap: userPassword
ad: userPassword ad: userPassword
logscript: logscript:
description: "Windows login script"
display_name: "Login script"
type: fix type: fix
value: login1.bat value: login1.bat
backend-attributes: backend-attributes:

View File

@ -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 from ldapcherry.exceptions import MissingAttributesFile, MissingKey
from sets import Set from sets import Set
import yaml import yaml
@ -30,6 +30,14 @@ class Attributes:
except DumplicatedKey as e: except DumplicatedKey as e:
raise DumplicateAttributesKey(e.key) 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): def get_selfattributes(self):
"""get the list of groups from roles""" """get the list of groups from roles"""
pass pass

View File

@ -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

View File

@ -8,7 +8,7 @@ import pytest
import sys import sys
from sets import Set from sets import Set
from ldapcherry.attributes import Attributes from ldapcherry.attributes import Attributes
from ldapcherry.exceptions import MissingAttributesFile from ldapcherry.exceptions import MissingAttributesFile, MissingKey
from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError
class TestError(object): class TestError(object):
@ -25,14 +25,14 @@ class TestError(object):
else: else:
raise AssertionError("expected an exception") raise AssertionError("expected an exception")
# def testMissingDisplayName(self): def testMissingMandatory(self):
# try: try:
# inv = Attributes('./tests/cfg/attributes_missing_diplay_name.yml') inv = Attributes('./tests/cfg/attributes_missing_mandatory.yml')
# except MissingKey: except MissingKey:
# return return
# else: else:
# raise AssertionError("expected an exception") raise AssertionError("expected an exception")
#
# def testAttrKeyDuplication(self): # def testAttrKeyDuplication(self):
# try: # try:
# inv = Attributes('./tests/cfg/attributes_key_dup.yml') # inv = Attributes('./tests/cfg/attributes_key_dup.yml')