Page MenuHomec4science

directory.py
No OneTemporary

File Metadata

Created
Sat, Nov 9, 23:38

directory.py

# -*- coding: utf-8 -*-
import ldap3
import copy
import re
from ... import export
from ... import colored
from ... import color_code
from ..directories.ldap import LDAPDirectory
__author__ = "Nicolas Richart"
__copyright__ = "Copyright (C) 2016, EPFL (Ecole Polytechnique Fédérale " \
"de Lausanne) - SCITAS (Scientific IT and Application " \
"Support)"
__credits__ = ["Nicolas Richart"]
__license__ = "BSD"
__version__ = "0.1"
__maintainer__ = "Nicolas Richart"
__email__ = "nicolas.richart@epfl.ch"
@export
class EPFLDirectory(LDAPDirectory):
def __init__(self, **kwargs):
args = copy.copy(kwargs)
args.update({
'basedn': 'o=epfl,c=ch',
'scope': ldap3.SUBTREE,
'uidNumber': 'uniqueIdentifier',
'gecos': 'gecos',
'uid': 'uid',
'email': 'mail',
'user_filter': '(&(objectClass=posixAccount)({attr}={value}))',
'user_group_attrs': 'memberOf',
'gidNumber': 'uniqueIdentifier',
'gid': 'cn',
'group_filter': '(&(objectClass=groupOfNames)({attr}={value}))',
'group_member_filter': 'uniqueIdentifier',
'group_user_attrs': 'memberUniqueId'
})
super().__init__('ldaps://scoldap.epfl.ch', **args)
def color_name(self, name, **kwargs):
regex = re.compile(r'([US]?)(G?)([0-9]+)')
match = regex.match(name)
if match:
if match.group(1):
return colored(name, color_code['group'])
else:
return colored(name, color_code['user'])
else:
return super().color_name(name, **kwargs)
def get_switch_aai_id(self, _id):
return '{0}@epfl.ch'.format(_id)

Event Timeline