mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-22 01:14:21 +01:00
begin attributes handling manipulation
This commit is contained in:
parent
1211ab431b
commit
dbc88163dd
@ -1,53 +1,70 @@
|
|||||||
last-name:
|
cn:
|
||||||
description: "Last Name of the user"
|
description: "Firt Name and Display Name"
|
||||||
display_name: "Last Name"
|
display_name: "Display Name"
|
||||||
|
type: string
|
||||||
|
autofill:
|
||||||
|
function: cn
|
||||||
|
args:
|
||||||
|
- $first-name
|
||||||
|
- $name
|
||||||
backend-attributes:
|
backend-attributes:
|
||||||
ldap: cn
|
ldap: cn
|
||||||
ad: CN
|
ad: CN
|
||||||
|
|
||||||
first-name:
|
first-name:
|
||||||
description: "First name of the user"
|
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"
|
display_name: "Name"
|
||||||
|
type: string
|
||||||
backend-attributes:
|
backend-attributes:
|
||||||
ldap: sn
|
ldap: sn
|
||||||
ad: sn
|
ad: sn
|
||||||
email:
|
email:
|
||||||
description: "Email of the user"
|
description: "Email of the user"
|
||||||
display_name: "Name"
|
display_name: "Name"
|
||||||
|
type: email
|
||||||
autofill:
|
autofill:
|
||||||
function: email
|
function: email
|
||||||
args:
|
args:
|
||||||
- $first-name
|
- $first-name
|
||||||
- $last-name
|
- $last-name
|
||||||
- @example.com
|
- '@example.com'
|
||||||
backend-attributes:
|
backend-attributes:
|
||||||
ldap: cn
|
ldap: email
|
||||||
ad: CN
|
ad: EMAIL
|
||||||
uid:
|
uid:
|
||||||
description: "UID of the user"
|
description: "UID of the user"
|
||||||
display_name: "UID"
|
display_name: "UID"
|
||||||
|
type: string
|
||||||
autofill:
|
autofill:
|
||||||
function: uid
|
function: uid
|
||||||
args:
|
args:
|
||||||
- $first-name
|
- $first-name
|
||||||
- $last-name
|
- $last-name
|
||||||
backend-attributes:
|
backend-attributes:
|
||||||
ldap: uid
|
ldap: uid
|
||||||
ad: UID
|
ad: UID
|
||||||
uidNumber:
|
uidNumber:
|
||||||
description: "User ID Number of the user"
|
description: "User ID Number of the user"
|
||||||
display_name: "UID Number"
|
display_name: "UID Number"
|
||||||
|
type: int
|
||||||
autofill:
|
autofill:
|
||||||
function: uidNumber
|
function: uidNumber
|
||||||
args:
|
args:
|
||||||
- $first-name
|
- $first-name
|
||||||
- $last-name
|
- $last-name
|
||||||
backend-attributes:
|
backend-attributes:
|
||||||
ldap: uidNumber
|
ldap: uidNumber
|
||||||
ad: UIDNumber
|
ad: UIDNumber
|
||||||
gidNumber:
|
gidNumber:
|
||||||
description: "Group ID Number of the user"
|
description: "Group ID Number of the user"
|
||||||
display_name: "GID Number"
|
display_name: "GID Number"
|
||||||
|
type: int
|
||||||
default: 10000
|
default: 10000
|
||||||
backend-attributes:
|
backend-attributes:
|
||||||
ldap: gidNumber
|
ldap: gidNumber
|
||||||
@ -55,8 +72,8 @@ gidNumber:
|
|||||||
shell:
|
shell:
|
||||||
description: "Shell of the user"
|
description: "Shell of the user"
|
||||||
display_name: "Shell"
|
display_name: "Shell"
|
||||||
self: true
|
self: True
|
||||||
type: list
|
type: stringlist
|
||||||
values:
|
values:
|
||||||
- /bin/bash
|
- /bin/bash
|
||||||
- /bin/zsh
|
- /bin/zsh
|
||||||
@ -67,12 +84,13 @@ shell:
|
|||||||
home:
|
home:
|
||||||
description: "Home user path"
|
description: "Home user path"
|
||||||
display_name: "Home"
|
display_name: "Home"
|
||||||
|
type: string
|
||||||
autofill:
|
autofill:
|
||||||
function: home
|
function: home
|
||||||
args:
|
args:
|
||||||
- $first-name
|
- $first-name
|
||||||
- $last-name
|
- $last-name
|
||||||
- /home/
|
- /home/
|
||||||
backend-attributes:
|
backend-attributes:
|
||||||
ldap: home
|
ldap: home
|
||||||
ad: Home
|
ad: Home
|
||||||
@ -80,7 +98,7 @@ home:
|
|||||||
password:
|
password:
|
||||||
decription: "Password of the user"
|
decription: "Password of the user"
|
||||||
display_name: "Password"
|
display_name: "Password"
|
||||||
self: true
|
self: True
|
||||||
type: password
|
type: password
|
||||||
backend-attributes:
|
backend-attributes:
|
||||||
ldap: userPassword
|
ldap: userPassword
|
||||||
|
@ -8,15 +8,27 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
try:
|
from ldapcherry.pyyamlwrapper import loadNoDump
|
||||||
from yaml import CLoader as Loader, CDumper as Dumper
|
from ldapcherry.pyyamlwrapper import DumplicatedKey
|
||||||
except ImportError:
|
from ldapcherry.exceptions import MissingAttributesFile
|
||||||
from yaml import Loader, Dumper
|
from sets import Set
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
types = ['string', 'email', 'int', 'stringlist', 'fix', 'password']
|
||||||
|
|
||||||
class Attributes:
|
class Attributes:
|
||||||
|
|
||||||
def __init__(self, attributes_file):
|
def __init__(self, attributes_file):
|
||||||
pass
|
self.attributes_file = attributes_file
|
||||||
|
self.backends = Set([])
|
||||||
|
try:
|
||||||
|
stream = open(attributes_file, 'r')
|
||||||
|
except:
|
||||||
|
raise MissingAttributesFile(attributes_file)
|
||||||
|
try:
|
||||||
|
self.attributes = loadNoDump(stream)
|
||||||
|
except DumplicatedKey as e:
|
||||||
|
raise DumplicateAttributesKey(e.key)
|
||||||
|
|
||||||
def get_selfattributes(self):
|
def get_selfattributes(self):
|
||||||
"""get the list of groups from roles"""
|
"""get the list of groups from roles"""
|
||||||
|
@ -38,3 +38,8 @@ class MissingRolesFile(Exception):
|
|||||||
def __init__(self, rolefile):
|
def __init__(self, rolefile):
|
||||||
self.rolefile = rolefile
|
self.rolefile = rolefile
|
||||||
self.log = "fail to open role file <%(rolefile)s>" % { 'rolefile' : rolefile}
|
self.log = "fail to open role file <%(rolefile)s>" % { 'rolefile' : rolefile}
|
||||||
|
|
||||||
|
class MissingAttributesFile(Exception):
|
||||||
|
def __init__(self, attributesfile):
|
||||||
|
self.attributesfile = attributesfile
|
||||||
|
self.log = "fail to open attributes file <%(attributesfile)s>" % { 'attributesfile' : attributesfile}
|
||||||
|
18
misc/debug_attributes.py
Normal file
18
misc/debug_attributes.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from ldapcherry.attributes import Attributes
|
||||||
|
from ldapcherry.exceptions import DumplicateRoleKey, MissingKey, DumplicateRoleContent, MissingRolesFile
|
||||||
|
from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError
|
||||||
|
from yaml import load, dump
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
try:
|
||||||
|
from yaml import CLoader as Loader, CDumper as Dumper
|
||||||
|
except ImportError:
|
||||||
|
from yaml import Loader, Dumper
|
||||||
|
|
||||||
|
class CustomDumper(yaml.SafeDumper):
|
||||||
|
"A custom YAML dumper that never emits aliases"
|
||||||
|
|
||||||
|
def ignore_aliases(self, _data):
|
||||||
|
return True
|
||||||
|
|
||||||
|
inv = Attributes('./conf/attributes.yml')
|
1
tests/cfg/attributes.yml
Symbolic link
1
tests/cfg/attributes.yml
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../conf/attributes.yml
|
59
tests/test_Attributes.py
Normal file
59
tests/test_Attributes.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import with_statement
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import sys
|
||||||
|
from sets import Set
|
||||||
|
from ldapcherry.attributes import Attributes
|
||||||
|
from ldapcherry.exceptions import MissingAttributesFile
|
||||||
|
from ldapcherry.pyyamlwrapper import DumplicatedKey, RelationError
|
||||||
|
|
||||||
|
class TestError(object):
|
||||||
|
|
||||||
|
def testNominal(self):
|
||||||
|
inv = Attributes('./tests/cfg/attributes.yml')
|
||||||
|
return True
|
||||||
|
|
||||||
|
def testNoFile(self):
|
||||||
|
try:
|
||||||
|
inv = Attributes('./tests/cfg/dontexist')
|
||||||
|
except MissingAttributesFile:
|
||||||
|
return
|
||||||
|
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 testAttrKeyDuplication(self):
|
||||||
|
# try:
|
||||||
|
# inv = Attributes('./tests/cfg/attributes_key_dup.yml')
|
||||||
|
# except DumplicateAttrKey:
|
||||||
|
# return
|
||||||
|
# else:
|
||||||
|
# raise AssertionError("expected an exception")
|
||||||
|
#
|
||||||
|
|
||||||
|
# def testGetDisplayNameMissingAttr(self):
|
||||||
|
# inv = Attributes('./tests/cfg/attributes.yml')
|
||||||
|
# try:
|
||||||
|
# res = inv.get_display_name('notarole')
|
||||||
|
# except MissingAttr:
|
||||||
|
# return
|
||||||
|
# else:
|
||||||
|
# raise AssertionError("expected an exception")
|
||||||
|
#
|
||||||
|
# def testGetDisplayName(self):
|
||||||
|
# inv = Attributes('./tests/cfg/attributes.yml')
|
||||||
|
# res = inv.get_display_name('users')
|
||||||
|
# expected = 'Simple Users'
|
||||||
|
# assert res == expected
|
||||||
|
#
|
Loading…
Reference in New Issue
Block a user