Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91320141
directory.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Nov 9, 23:38
Size
1 KB
Mime Type
text/x-python
Expires
Mon, Nov 11, 23:38 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22242452
Attached To
rPHAPI Phabricator API scripts
directory.py
View Options
# -*- 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
Log In to Comment