Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pygitlab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fsl
pygitlab
Commits
ea1682d0
Commit
ea1682d0
authored
8 years ago
by
artem
Committed by
jakob
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
searching for users in ldap by dict-specified arguments
parent
e49ff17e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ldap.py
+10
-22
10 additions, 22 deletions
ldap.py
with
10 additions
and
22 deletions
ldap.py
+
10
−
22
View file @
ea1682d0
...
@@ -7,28 +7,16 @@ class LdapHandler:
...
@@ -7,28 +7,16 @@ class LdapHandler:
self
.
connection
=
ldap3
.
Connection
(
server
,
auto_bind
=
True
)
self
.
connection
=
ldap3
.
Connection
(
server
,
auto_bind
=
True
)
self
.
default_context
=
default_context
self
.
default_context
=
default_context
def
get_ldap_user
(
self
,
search_filter
:
dict
,
silent
:
bool
=
False
,
context
:
str
=
'
__USEDEFAULT__
'
,
def
get_ldap_users
(
self
,
user_list
:
list
,
silent
:
bool
=
False
,
context
:
str
=
'
__USEDEFAULT__
'
):
attributes
:
list
=
[
'
sn
'
,
'
gn
'
,
'
objectclass
'
]):
results
=
[]
if
context
==
'
__USEDEFAULT__
'
:
if
context
==
'
__USEDEFAULT
'
:
search_context
=
self
.
default_context
search_context
=
self
.
default_context
else
:
else
:
search_context
=
context
search_context
=
context
i
=
1
for
user
in
user_list
:
search_string
=
"
(&
"
user
=
user
.
strip
()
for
key
,
value
in
search_filter
.
items
():
if
not
silent
:
search_string
+=
'
(
'
+
key
+
'
=
'
+
value
+
'
)
'
print
(
"
%s (%d/%d)
"
%
(
user
,
i
,
len
(
results
)))
search_string
+=
'
)
'
search_no
=
self
.
ldap
.
search
(
search_context
,
ldap3
.
SCOPE_SUBTREE
,
"
uid=%s
"
%
user
,
None
)
search_res
=
self
.
ldap
.
result
(
search_no
,
0
)
self
.
connection
.
search
(
search_context
,
search_string
,
attributes
=
attributes
)
if
search_res
[
0
]
==
100
:
dn
=
search_res
[
1
][
0
][
0
]
name
=
search_res
[
1
][
0
][
1
][
'
cn
'
][
0
]
mail
=
search_res
[
1
][
0
][
1
][
'
mail
'
][
0
]
location
=
search_res
[
1
][
0
][
1
][
'
l
'
][
0
]
results
.
append
({
'
dn
'
:
dn
,
'
username
'
:
user
,
'
name
'
:
name
,
'
mail
'
:
mail
,
'
location
'
:
location
})
return
results
def
connect
(
ldaphost
:
str
,
default_context
:
str
=
''
,
ssl
:
bool
=
False
)
->
LdapHandler
:
return
LdapHandler
(
ldaphost
,
default_context
,
ssl
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment