Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uffd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Luca (strifel)
uffd
Commits
245aba18
Commit
245aba18
authored
4 years ago
by
Julian
Browse files
Options
Downloads
Patches
Plain Diff
Added guery functions to session
parent
986d7c09
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ldap3_mapper_new/base.py
+39
-3
39 additions, 3 deletions
ldap3_mapper_new/base.py
with
39 additions
and
3 deletions
ldap3_mapper_new/base.py
+
39
−
3
View file @
245aba18
...
@@ -71,6 +71,7 @@ class Session:
...
@@ -71,6 +71,7 @@ class Session:
ldap_mapper
=
None
ldap_mapper
=
None
def
__init__
(
self
):
def
__init__
(
self
):
self
.
__objects
=
{}
self
.
__operations
=
[]
self
.
__operations
=
[]
def
record
(
self
,
obj
,
oper
):
def
record
(
self
,
obj
,
oper
):
...
@@ -94,7 +95,7 @@ class Session:
...
@@ -94,7 +95,7 @@ class Session:
self
.
__operations
.
append
((
obj
,
oper
))
self
.
__operations
.
append
((
obj
,
oper
))
def
commit
(
self
):
def
commit
(
self
):
conn
=
self
.
ldap_
mapper
.
connect
()
conn
=
self
.
mapper
.
connect
()
while
self
.
__operations
:
while
self
.
__operations
:
obj
,
oper
=
self
.
__operations
.
pop
(
0
)
obj
,
oper
=
self
.
__operations
.
pop
(
0
)
try
:
try
:
...
@@ -109,6 +110,38 @@ class Session:
...
@@ -109,6 +110,38 @@ class Session:
obj
,
oper
=
self
.
__operations
.
pop
(
0
)
obj
,
oper
=
self
.
__operations
.
pop
(
0
)
obj
.
ldap_state
.
current
=
obj
.
ldap_state
.
committed
.
copy
()
obj
.
ldap_state
.
current
=
obj
.
ldap_state
.
committed
.
copy
()
def
query_get
(
self
,
cls
,
dn
):
if
dn
in
self
.
__objects
:
return
self
.
__objects
[
dn
]
if
dn
in
self
.
__deleted_objects
:
return
None
conn
=
self
.
mapper
.
connect
()
conn
.
search
(
dn
,
cls
.
ldap_filter
,
attributes
=
[
ALL_ATTRIBUTES
,
ALL_OPERATIONAL_ATTRIBUTES
])
if
not
conn
.
response
:
return
None
self
.
__objects
[
dn
]
=
cls
(
__ldap_response
=
conn
.
response
[
0
])
return
self
.
__objects
[
dn
]
def
query_search
(
self
,
cls
,
filters
=
None
):
filters
=
[
cls
.
ldap_filter
]
+
(
filters
or
[])
if
len
(
filters
)
==
1
:
expr
=
filters
[
0
]
else
:
expr
=
'
(&%s)
'
%
(
''
.
join
(
filters
))
conn
=
self
.
mapper
.
connect
()
conn
.
search
(
cls
.
ldap_base
,
cls
.
ldap_filter
,
attributes
=
[
ALL_ATTRIBUTES
,
ALL_OPERATIONAL_ATTRIBUTES
])
res
=
[]
for
response
in
conn
.
response
:
dn
=
response
[
'
dn
'
]
if
dn
in
self
.
__objects
:
res
.
append
(
self
.
__objects
[
dn
])
elif
dn
in
self
.
__deleted_objects
:
continue
else
:
self
.
__objects
[
dn
]
=
cls
(
__ldap_response
=
response
)
res
.
append
(
self
.
__objects
[
dn
])
return
res
# This is only a seperate class to keep SessionObject's namespace cleaner
# This is only a seperate class to keep SessionObject's namespace cleaner
class
SessionObjectState
:
class
SessionObjectState
:
def
__init__
(
self
,
obj
,
response
=
None
):
def
__init__
(
self
,
obj
,
response
=
None
):
...
@@ -142,12 +175,15 @@ class SessionObjectState:
...
@@ -142,12 +175,15 @@ class SessionObjectState:
self
.
session
.
record
(
self
.
obj
,
oper
)
self
.
session
.
record
(
self
.
obj
,
oper
)
oper
.
apply
(
self
.
current
)
oper
.
apply
(
self
.
current
)
# This is only a seperate class to keep SessionObject's namespace cleaner
class
SessionObject
:
class
SessionObject
:
ldap_mapper
=
None
ldap_mapper
=
None
ldap_object_classes
=
None
ldap_object_classes
=
None
ldap_base
=
None
ldap_filter
=
None
def
__init__
(
self
,
response
=
None
):
def
__init__
(
self
,
__ldap_
response
=
None
):
self
.
ldap_state
=
SessionObjectState
(
self
,
response
)
self
.
ldap_state
=
SessionObjectState
(
self
,
__ldap_
response
)
@property
@property
def
dn
(
self
):
def
dn
(
self
):
...
...
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