Skip to content

Commit

Permalink
begin attributes handling manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
kakwa committed May 17, 2015
1 parent 1211ab4 commit dbc8816
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 28 deletions.
64 changes: 41 additions & 23 deletions conf/attributes.yml
@@ -1,62 +1,79 @@
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
ad: GIDNumber
shell:
description: "Shell of the user"
display_name: "Shell"
self: true
type: list
self: True
type: stringlist
values:
- /bin/bash
- /bin/zsh
Expand All @@ -67,20 +84,21 @@ 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

password:
decription: "Password of the user"
display_name: "Password"
self: true
self: True
type: password
backend-attributes:
ldap: userPassword
Expand Down
22 changes: 17 additions & 5 deletions ldapcherry/attributes.py
Expand Up @@ -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"""
Expand Down
5 changes: 5 additions & 0 deletions ldapcherry/exceptions.py
Expand Up @@ -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 changes: 18 additions & 0 deletions misc/debug_attributes.py
@@ -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 change: 1 addition & 0 deletions tests/cfg/attributes.yml
59 changes: 59 additions & 0 deletions tests/test_Attributes.py
@@ -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
#

0 comments on commit dbc8816

Please sign in to comment.