mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-21 17:04:21 +01:00
begin attributes handling manipulation
This commit is contained in:
parent
1211ab431b
commit
dbc88163dd
@ -1,53 +1,70 @@
|
||||
last-name:
|
||||
description: "Last Name of the user"
|
||||
display_name: "Last Name"
|
||||
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
|
||||
args:
|
||||
- $first-name
|
||||
- $last-name
|
||||
- '@example.com'
|
||||
backend-attributes:
|
||||
ldap: cn
|
||||
ad: CN
|
||||
ldap: email
|
||||
ad: EMAIL
|
||||
uid:
|
||||
description: "UID of the user"
|
||||
display_name: "UID"
|
||||
type: string
|
||||
autofill:
|
||||
function: uid
|
||||
args:
|
||||
- $first-name
|
||||
- $last-name
|
||||
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
|
||||
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
|
||||
@ -55,8 +72,8 @@ gidNumber:
|
||||
shell:
|
||||
description: "Shell of the user"
|
||||
display_name: "Shell"
|
||||
self: true
|
||||
type: list
|
||||
self: True
|
||||
type: stringlist
|
||||
values:
|
||||
- /bin/bash
|
||||
- /bin/zsh
|
||||
@ -67,12 +84,13 @@ shell:
|
||||
home:
|
||||
description: "Home user path"
|
||||
display_name: "Home"
|
||||
type: string
|
||||
autofill:
|
||||
function: home
|
||||
args:
|
||||
- $first-name
|
||||
- $last-name
|
||||
- /home/
|
||||
args:
|
||||
- $first-name
|
||||
- $last-name
|
||||
- /home/
|
||||
backend-attributes:
|
||||
ldap: home
|
||||
ad: Home
|
||||
@ -80,7 +98,7 @@ home:
|
||||
password:
|
||||
decription: "Password of the user"
|
||||
display_name: "Password"
|
||||
self: true
|
||||
self: True
|
||||
type: password
|
||||
backend-attributes:
|
||||
ldap: userPassword
|
||||
|
@ -8,15 +8,27 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
try:
|
||||
from yaml import CLoader as Loader, CDumper as Dumper
|
||||
except ImportError:
|
||||
from yaml import Loader, Dumper
|
||||
from ldapcherry.pyyamlwrapper import loadNoDump
|
||||
from ldapcherry.pyyamlwrapper import DumplicatedKey
|
||||
from ldapcherry.exceptions import MissingAttributesFile
|
||||
from sets import Set
|
||||
import yaml
|
||||
|
||||
types = ['string', 'email', 'int', 'stringlist', 'fix', 'password']
|
||||
|
||||
class Attributes:
|
||||
|
||||
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):
|
||||
"""get the list of groups from roles"""
|
||||
|
@ -38,3 +38,8 @@ class MissingRolesFile(Exception):
|
||||
def __init__(self, rolefile):
|
||||
self.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