mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-22 01:14:21 +01:00
adding checks for mandatory elements of attributes.yml
This commit is contained in:
parent
dbc88163dd
commit
679c2bba85
@ -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:
|
||||
|
@ -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
|
||||
|
111
tests/cfg/attributes_missing_mandatory.yml
Normal file
111
tests/cfg/attributes_missing_mandatory.yml
Normal 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
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user